@fredlackey/devutils 0.0.1 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (259) hide show
  1. package/README.md +5 -5
  2. package/package.json +1 -1
  3. package/src/commands/install.js +374 -36
  4. package/src/installs/adobe-creative-cloud.js +527 -25
  5. package/src/installs/adobe-creative-cloud.md +605 -0
  6. package/src/installs/appcleaner.js +303 -26
  7. package/src/installs/appcleaner.md +699 -0
  8. package/src/installs/apt-transport-https.js +390 -0
  9. package/src/installs/apt-transport-https.md +678 -0
  10. package/src/installs/atomicparsley.js +624 -26
  11. package/src/installs/atomicparsley.md +795 -0
  12. package/src/installs/aws-cli.js +779 -26
  13. package/src/installs/aws-cli.md +727 -0
  14. package/src/installs/balena-etcher.js +688 -26
  15. package/src/installs/balena-etcher.md +761 -0
  16. package/src/installs/bambu-studio.js +912 -26
  17. package/src/installs/bambu-studio.md +780 -0
  18. package/src/installs/bash-completion.js +554 -23
  19. package/src/installs/bash-completion.md +833 -0
  20. package/src/installs/bash.js +399 -26
  21. package/src/installs/bash.md +993 -0
  22. package/src/installs/beyond-compare.js +585 -26
  23. package/src/installs/beyond-compare.md +813 -0
  24. package/src/installs/build-essential.js +511 -26
  25. package/src/installs/build-essential.md +977 -0
  26. package/src/installs/ca-certificates.js +618 -0
  27. package/src/installs/ca-certificates.md +937 -0
  28. package/src/installs/caffeine.js +490 -26
  29. package/src/installs/caffeine.md +839 -0
  30. package/src/installs/camtasia.js +577 -25
  31. package/src/installs/camtasia.md +762 -0
  32. package/src/installs/chatgpt.js +458 -26
  33. package/src/installs/chatgpt.md +814 -0
  34. package/src/installs/chocolatey.js +447 -0
  35. package/src/installs/chocolatey.md +661 -0
  36. package/src/installs/chrome-canary.js +472 -26
  37. package/src/installs/chrome-canary.md +641 -0
  38. package/src/installs/chromium.js +645 -26
  39. package/src/installs/chromium.md +838 -0
  40. package/src/installs/claude-code.js +558 -26
  41. package/src/installs/claude-code.md +1173 -0
  42. package/src/installs/curl.js +361 -26
  43. package/src/installs/curl.md +714 -0
  44. package/src/installs/cursor.js +561 -26
  45. package/src/installs/cursor.md +970 -0
  46. package/src/installs/dbschema.js +674 -26
  47. package/src/installs/dbschema.md +925 -0
  48. package/src/installs/dependencies.md +435 -0
  49. package/src/installs/development-tools.js +600 -0
  50. package/src/installs/development-tools.md +977 -0
  51. package/src/installs/docker.js +1010 -25
  52. package/src/installs/docker.md +1109 -0
  53. package/src/installs/drawio.js +1001 -26
  54. package/src/installs/drawio.md +795 -0
  55. package/src/installs/elmedia-player.js +328 -25
  56. package/src/installs/elmedia-player.md +556 -0
  57. package/src/installs/ffmpeg.js +870 -25
  58. package/src/installs/ffmpeg.md +852 -0
  59. package/src/installs/file.js +464 -0
  60. package/src/installs/file.md +987 -0
  61. package/src/installs/gemini-cli.js +793 -26
  62. package/src/installs/gemini-cli.md +1153 -0
  63. package/src/installs/git.js +382 -26
  64. package/src/installs/git.md +907 -0
  65. package/src/installs/gitego.js +931 -26
  66. package/src/installs/gitego.md +1172 -0
  67. package/src/installs/go.js +913 -26
  68. package/src/installs/go.md +958 -0
  69. package/src/installs/google-chrome.js +801 -25
  70. package/src/installs/google-chrome.md +862 -0
  71. package/src/installs/gpg.js +412 -73
  72. package/src/installs/gpg.md +1056 -0
  73. package/src/installs/homebrew.js +1015 -26
  74. package/src/installs/homebrew.md +988 -0
  75. package/src/installs/imageoptim.js +950 -26
  76. package/src/installs/imageoptim.md +1119 -0
  77. package/src/installs/installers.json +2297 -0
  78. package/src/installs/jq.js +382 -26
  79. package/src/installs/jq.md +809 -0
  80. package/src/installs/keyboard-maestro.js +701 -26
  81. package/src/installs/keyboard-maestro.md +825 -0
  82. package/src/installs/latex.js +771 -26
  83. package/src/installs/latex.md +1095 -0
  84. package/src/installs/lftp.js +338 -26
  85. package/src/installs/lftp.md +907 -0
  86. package/src/installs/lsb-release.js +346 -0
  87. package/src/installs/lsb-release.md +814 -0
  88. package/src/installs/messenger.js +829 -26
  89. package/src/installs/messenger.md +900 -0
  90. package/src/installs/microsoft-office.js +550 -26
  91. package/src/installs/microsoft-office.md +760 -0
  92. package/src/installs/microsoft-teams.js +782 -25
  93. package/src/installs/microsoft-teams.md +886 -0
  94. package/src/installs/node.js +886 -26
  95. package/src/installs/node.md +1153 -0
  96. package/src/installs/nordpass.js +698 -26
  97. package/src/installs/nordpass.md +921 -0
  98. package/src/installs/nvm.js +977 -26
  99. package/src/installs/nvm.md +1057 -0
  100. package/src/installs/openssh.js +734 -64
  101. package/src/installs/openssh.md +1056 -0
  102. package/src/installs/pandoc.js +644 -26
  103. package/src/installs/pandoc.md +1036 -0
  104. package/src/installs/pinentry.js +492 -26
  105. package/src/installs/pinentry.md +1142 -0
  106. package/src/installs/pngyu.js +851 -26
  107. package/src/installs/pngyu.md +896 -0
  108. package/src/installs/postman.js +781 -26
  109. package/src/installs/postman.md +940 -0
  110. package/src/installs/procps.js +425 -0
  111. package/src/installs/procps.md +851 -0
  112. package/src/installs/safari-tech-preview.js +355 -25
  113. package/src/installs/safari-tech-preview.md +533 -0
  114. package/src/installs/sfnt2woff.js +640 -26
  115. package/src/installs/sfnt2woff.md +795 -0
  116. package/src/installs/shellcheck.js +463 -26
  117. package/src/installs/shellcheck.md +1005 -0
  118. package/src/installs/slack.js +722 -25
  119. package/src/installs/slack.md +865 -0
  120. package/src/installs/snagit.js +566 -25
  121. package/src/installs/snagit.md +844 -0
  122. package/src/installs/software-properties-common.js +372 -0
  123. package/src/installs/software-properties-common.md +805 -0
  124. package/src/installs/spotify.js +858 -25
  125. package/src/installs/spotify.md +901 -0
  126. package/src/installs/studio-3t.js +803 -26
  127. package/src/installs/studio-3t.md +918 -0
  128. package/src/installs/sublime-text.js +780 -25
  129. package/src/installs/sublime-text.md +914 -0
  130. package/src/installs/superwhisper.js +687 -25
  131. package/src/installs/superwhisper.md +630 -0
  132. package/src/installs/tailscale.js +727 -26
  133. package/src/installs/tailscale.md +1100 -0
  134. package/src/installs/tar.js +389 -0
  135. package/src/installs/tar.md +946 -0
  136. package/src/installs/termius.js +780 -26
  137. package/src/installs/termius.md +844 -0
  138. package/src/installs/terraform.js +761 -26
  139. package/src/installs/terraform.md +899 -0
  140. package/src/installs/tidal.js +752 -25
  141. package/src/installs/tidal.md +864 -0
  142. package/src/installs/tmux.js +328 -26
  143. package/src/installs/tmux.md +1030 -0
  144. package/src/installs/tree.js +393 -26
  145. package/src/installs/tree.md +833 -0
  146. package/src/installs/unzip.js +460 -0
  147. package/src/installs/unzip.md +879 -0
  148. package/src/installs/vim.js +403 -26
  149. package/src/installs/vim.md +1040 -0
  150. package/src/installs/vlc.js +803 -26
  151. package/src/installs/vlc.md +927 -0
  152. package/src/installs/vscode.js +825 -26
  153. package/src/installs/vscode.md +1002 -0
  154. package/src/installs/wget.js +415 -0
  155. package/src/installs/wget.md +791 -0
  156. package/src/installs/whatsapp.js +710 -25
  157. package/src/installs/whatsapp.md +854 -0
  158. package/src/installs/winpty.js +352 -0
  159. package/src/installs/winpty.md +620 -0
  160. package/src/installs/woff2.js +535 -26
  161. package/src/installs/woff2.md +977 -0
  162. package/src/installs/wsl.js +572 -0
  163. package/src/installs/wsl.md +699 -0
  164. package/src/installs/xcode-clt.js +520 -0
  165. package/src/installs/xcode-clt.md +351 -0
  166. package/src/installs/xcode.js +542 -26
  167. package/src/installs/xcode.md +573 -0
  168. package/src/installs/yarn.js +806 -26
  169. package/src/installs/yarn.md +1074 -0
  170. package/src/installs/yq.js +636 -26
  171. package/src/installs/yq.md +944 -0
  172. package/src/installs/yt-dlp.js +683 -26
  173. package/src/installs/yt-dlp.md +946 -0
  174. package/src/installs/yum-utils.js +297 -0
  175. package/src/installs/yum-utils.md +648 -0
  176. package/src/installs/zoom.js +740 -25
  177. package/src/installs/zoom.md +884 -0
  178. package/src/scripts/README.md +567 -45
  179. package/src/scripts/STATUS.md +208 -0
  180. package/src/scripts/afk.js +395 -7
  181. package/src/scripts/backup-all.js +731 -9
  182. package/src/scripts/backup-source.js +711 -8
  183. package/src/scripts/brewd.js +373 -7
  184. package/src/scripts/brewi.js +505 -9
  185. package/src/scripts/brewr.js +512 -9
  186. package/src/scripts/brews.js +462 -9
  187. package/src/scripts/brewu.js +488 -7
  188. package/src/scripts/c.js +185 -7
  189. package/src/scripts/ccurl.js +325 -8
  190. package/src/scripts/certbot-crontab-init.js +488 -8
  191. package/src/scripts/certbot-init.js +641 -9
  192. package/src/scripts/ch.js +339 -7
  193. package/src/scripts/claude-danger.js +253 -8
  194. package/src/scripts/clean-dev.js +419 -8
  195. package/src/scripts/clear-dns-cache.js +525 -7
  196. package/src/scripts/clone.js +417 -7
  197. package/src/scripts/code-all.js +420 -7
  198. package/src/scripts/count-files.js +195 -8
  199. package/src/scripts/count-folders.js +195 -8
  200. package/src/scripts/count.js +248 -8
  201. package/src/scripts/d.js +203 -7
  202. package/src/scripts/datauri.js +373 -8
  203. package/src/scripts/delete-files.js +363 -7
  204. package/src/scripts/docker-clean.js +410 -8
  205. package/src/scripts/dp.js +426 -7
  206. package/src/scripts/e.js +375 -9
  207. package/src/scripts/empty-trash.js +497 -7
  208. package/src/scripts/evm.js +428 -9
  209. package/src/scripts/fetch-github-repos.js +441 -10
  210. package/src/scripts/get-channel.js +329 -8
  211. package/src/scripts/get-course.js +384 -11
  212. package/src/scripts/get-dependencies.js +290 -9
  213. package/src/scripts/get-folder.js +783 -10
  214. package/src/scripts/get-tunes.js +411 -10
  215. package/src/scripts/get-video.js +352 -9
  216. package/src/scripts/git-backup.js +561 -9
  217. package/src/scripts/git-clone.js +477 -9
  218. package/src/scripts/git-pup.js +303 -7
  219. package/src/scripts/git-push.js +380 -8
  220. package/src/scripts/h.js +607 -9
  221. package/src/scripts/hide-desktop-icons.js +483 -7
  222. package/src/scripts/hide-hidden-files.js +522 -7
  223. package/src/scripts/install-dependencies-from.js +440 -9
  224. package/src/scripts/ips.js +647 -10
  225. package/src/scripts/iso.js +354 -8
  226. package/src/scripts/killni.js +561 -7
  227. package/src/scripts/ll.js +451 -8
  228. package/src/scripts/local-ip.js +310 -8
  229. package/src/scripts/m.js +508 -8
  230. package/src/scripts/map.js +293 -8
  231. package/src/scripts/mkd.js +287 -7
  232. package/src/scripts/ncu-update-all.js +441 -8
  233. package/src/scripts/nginx-init.js +702 -12
  234. package/src/scripts/npmi.js +366 -7
  235. package/src/scripts/o.js +495 -8
  236. package/src/scripts/org-by-date.js +321 -7
  237. package/src/scripts/p.js +208 -7
  238. package/src/scripts/packages.js +313 -8
  239. package/src/scripts/path.js +209 -7
  240. package/src/scripts/ports.js +582 -8
  241. package/src/scripts/q.js +290 -8
  242. package/src/scripts/refresh-files.js +378 -10
  243. package/src/scripts/remove-smaller-files.js +500 -8
  244. package/src/scripts/rename-files-with-date.js +517 -9
  245. package/src/scripts/resize-image.js +523 -9
  246. package/src/scripts/rm-safe.js +653 -8
  247. package/src/scripts/s.js +525 -9
  248. package/src/scripts/set-git-public.js +349 -7
  249. package/src/scripts/show-desktop-icons.js +459 -7
  250. package/src/scripts/show-hidden-files.js +456 -7
  251. package/src/scripts/tpa.js +265 -8
  252. package/src/scripts/tpo.js +264 -7
  253. package/src/scripts/u.js +489 -7
  254. package/src/scripts/vpush.js +422 -8
  255. package/src/scripts/y.js +267 -7
  256. package/src/utils/common/os.js +94 -2
  257. package/src/utils/ubuntu/apt.js +13 -7
  258. package/src/utils/windows/choco.js +82 -26
  259. package/src/utils/windows/winget.js +89 -27
@@ -1,23 +1,513 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  /**
4
- * @fileoverview Empty all trash and system logs.
4
+ * empty-trash - Empty all trash and system logs to free disk space
5
+ *
6
+ * Migrated from legacy dotfiles alias.
7
+ * Original aliases:
8
+ * macOS: alias empty-trash="sudo rm -frv /Volumes/\*\/.Trashes; \
9
+ * sudo rm -frv ~/.Trash; \
10
+ * sudo rm -frv /private/var/log/asl/\*.asl; \
11
+ * sqlite3 ~/Library/Preferences/com.apple.LaunchServices.QuarantineEventsV\* 'delete from LSQuarantineEvent'"
12
+ * Ubuntu: alias empty-trash="rm -rf ~/.local/share/Trash/files/\*"
13
+ *
14
+ * This script empties the user's trash folder(s) and clears system logs
15
+ * to free up disk space. The exact behavior varies by platform:
16
+ * - macOS: Clears user trash, mounted volume trash, system logs, and quarantine database
17
+ * - Linux: Clears the XDG trash directory (~/.local/share/Trash/)
18
+ * - Windows: Empties the Recycle Bin
19
+ *
5
20
  * @module scripts/empty-trash
6
21
  */
7
22
 
23
+ const os = require('../utils/common/os');
24
+ const { execSync, exec } = require('child_process');
25
+ const fs = require('fs');
26
+ const path = require('path');
27
+
28
+ /**
29
+ * Helper function to check if a command exists on the system.
30
+ *
31
+ * @param {string} cmd - The command name to check
32
+ * @returns {boolean} True if the command exists, false otherwise
33
+ */
34
+ function isCommandAvailable(cmd) {
35
+ try {
36
+ const checkCmd = process.platform === 'win32' ? `where ${cmd}` : `which ${cmd}`;
37
+ execSync(checkCmd, { stdio: 'ignore' });
38
+ return true;
39
+ } catch {
40
+ return false;
41
+ }
42
+ }
43
+
44
+ /**
45
+ * Recursively delete all contents of a directory using pure Node.js.
46
+ * The directory itself is preserved, only its contents are removed.
47
+ *
48
+ * This is a helper function that handles the core logic of emptying
49
+ * a trash folder without needing to shell out to rm -rf.
50
+ *
51
+ * @param {string} dirPath - Absolute path to the directory to empty
52
+ * @param {boolean} verbose - If true, print each file/folder being deleted
53
+ * @returns {{ deleted: number, errors: string[] }} Count of deleted items and any errors
54
+ */
55
+ function emptyDirectory(dirPath, verbose = false) {
56
+ const result = { deleted: 0, errors: [] };
57
+
58
+ // Check if directory exists
59
+ if (!fs.existsSync(dirPath)) {
60
+ return result;
61
+ }
62
+
63
+ try {
64
+ const entries = fs.readdirSync(dirPath, { withFileTypes: true });
65
+
66
+ for (const entry of entries) {
67
+ const fullPath = path.join(dirPath, entry.name);
68
+ try {
69
+ if (entry.isDirectory()) {
70
+ // Recursively remove directory and all its contents
71
+ fs.rmSync(fullPath, { recursive: true, force: true });
72
+ if (verbose) {
73
+ console.log(`Removed: ${fullPath}`);
74
+ }
75
+ } else {
76
+ // Remove file
77
+ fs.unlinkSync(fullPath);
78
+ if (verbose) {
79
+ console.log(`Removed: ${fullPath}`);
80
+ }
81
+ }
82
+ result.deleted++;
83
+ } catch (err) {
84
+ // Record error but continue with other files
85
+ result.errors.push(`${fullPath}: ${err.message}`);
86
+ }
87
+ }
88
+ } catch (err) {
89
+ result.errors.push(`${dirPath}: ${err.message}`);
90
+ }
91
+
92
+ return result;
93
+ }
94
+
8
95
  /**
9
- * Empties the system trash, mounted volume trash, and clears
10
- * system logs to free up disk space.
96
+ * Pure Node.js implementation for emptying trash.
97
+ *
98
+ * This handles the common case of emptying the XDG trash directory
99
+ * which is used on most Linux systems. It can be used on any platform
100
+ * that follows the XDG trash specification.
101
+ *
102
+ * Note: This does NOT handle:
103
+ * - macOS system logs and quarantine database (requires shell commands)
104
+ * - Windows Recycle Bin (requires PowerShell/COM)
105
+ * - Mounted volume trash directories (requires sudo on macOS)
11
106
  *
12
107
  * @param {string[]} args - Command line arguments (unused)
13
108
  * @returns {Promise<void>}
14
109
  */
15
- async function main(args) {
16
- // TODO: Implement trash emptying
110
+ async function do_empty_trash_nodejs(args) {
111
+ const homeDir = os.getHomeDir();
112
+ const verbose = args.includes('-v') || args.includes('--verbose');
113
+
114
+ // XDG Trash specification directories
115
+ // See: https://specifications.freedesktop.org/trash-spec/trashspec-latest.html
116
+ const trashPaths = [
117
+ path.join(homeDir, '.local', 'share', 'Trash', 'files'),
118
+ path.join(homeDir, '.local', 'share', 'Trash', 'info'),
119
+ path.join(homeDir, '.local', 'share', 'Trash', 'expunged')
120
+ ];
121
+
122
+ let totalDeleted = 0;
123
+ const allErrors = [];
124
+
125
+ for (const trashPath of trashPaths) {
126
+ if (fs.existsSync(trashPath)) {
127
+ if (verbose) {
128
+ console.log(`Emptying: ${trashPath}`);
129
+ }
130
+ const result = emptyDirectory(trashPath, verbose);
131
+ totalDeleted += result.deleted;
132
+ allErrors.push(...result.errors);
133
+ }
134
+ }
135
+
136
+ if (totalDeleted > 0) {
137
+ console.log(`Trash emptied. Removed ${totalDeleted} item(s).`);
138
+ } else if (allErrors.length === 0) {
139
+ console.log('Trash is already empty.');
140
+ }
141
+
142
+ if (allErrors.length > 0) {
143
+ console.error('');
144
+ console.error('Some items could not be removed:');
145
+ for (const err of allErrors) {
146
+ console.error(` ${err}`);
147
+ }
148
+ }
149
+ }
150
+
151
+ /**
152
+ * Empty trash on macOS.
153
+ *
154
+ * This replicates the original dotfiles alias which does four things:
155
+ * 1. Remove .Trashes folders from all mounted volumes (requires sudo)
156
+ * 2. Remove the user's ~/.Trash folder contents (requires sudo)
157
+ * 3. Remove ASL (Apple System Log) files to improve shell startup speed
158
+ * 4. Clear the quarantine events database (download history)
159
+ *
160
+ * Note: Some operations require sudo/admin privileges. The script will
161
+ * attempt each operation and report any failures.
162
+ *
163
+ * @param {string[]} args - Command line arguments
164
+ * @returns {Promise<void>}
165
+ */
166
+ async function do_empty_trash_macos(args) {
167
+ const homeDir = os.getHomeDir();
168
+ const verbose = args.includes('-v') || args.includes('--verbose');
169
+ const results = [];
170
+
171
+ console.log('Emptying trash and clearing system logs...');
172
+
173
+ // 1. Empty user's Trash folder using Node.js (no sudo needed for user's own trash)
174
+ const userTrash = path.join(homeDir, '.Trash');
175
+ if (fs.existsSync(userTrash)) {
176
+ if (verbose) {
177
+ console.log(`\nEmptying user trash: ${userTrash}`);
178
+ }
179
+ const userTrashResult = emptyDirectory(userTrash, verbose);
180
+ if (userTrashResult.deleted > 0) {
181
+ results.push(`User trash: ${userTrashResult.deleted} item(s) removed`);
182
+ }
183
+ if (userTrashResult.errors.length > 0) {
184
+ console.error('Some files in user trash could not be removed (may need sudo).');
185
+ }
186
+ }
187
+
188
+ // 2. Try to empty mounted volumes' .Trashes folders
189
+ // This typically requires sudo, so we'll use shell command
190
+ try {
191
+ // First, find mounted volumes with .Trashes folders
192
+ if (fs.existsSync('/Volumes')) {
193
+ const volumes = fs.readdirSync('/Volumes');
194
+ for (const volume of volumes) {
195
+ const trashPath = path.join('/Volumes', volume, '.Trashes');
196
+ if (fs.existsSync(trashPath)) {
197
+ if (verbose) {
198
+ console.log(`\nFound volume trash: ${trashPath}`);
199
+ }
200
+ try {
201
+ // Try without sudo first (may work for user-owned files)
202
+ const result = emptyDirectory(trashPath, verbose);
203
+ if (result.deleted > 0) {
204
+ results.push(`${volume} trash: ${result.deleted} item(s) removed`);
205
+ }
206
+ } catch (err) {
207
+ // May need elevated privileges
208
+ if (verbose) {
209
+ console.log(`Could not empty ${trashPath} without sudo.`);
210
+ }
211
+ }
212
+ }
213
+ }
214
+ }
215
+ } catch (err) {
216
+ // Continue even if volume trash emptying fails
217
+ if (verbose) {
218
+ console.log('Could not access some volume trash folders.');
219
+ }
220
+ }
221
+
222
+ // 3. Clear ASL (Apple System Log) files to improve shell startup speed
223
+ // This requires sudo for system logs
224
+ const aslPath = '/private/var/log/asl';
225
+ if (fs.existsSync(aslPath)) {
226
+ try {
227
+ // Try to remove ASL files - this typically needs sudo
228
+ const aslFiles = fs.readdirSync(aslPath).filter(f => f.endsWith('.asl'));
229
+ if (aslFiles.length > 0) {
230
+ if (verbose) {
231
+ console.log(`\nFound ${aslFiles.length} ASL log file(s) to clear.`);
232
+ console.log('Note: Clearing system logs typically requires sudo.');
233
+ }
234
+ // Attempt to remove (will likely fail without sudo)
235
+ let removed = 0;
236
+ for (const file of aslFiles) {
237
+ try {
238
+ fs.unlinkSync(path.join(aslPath, file));
239
+ removed++;
240
+ } catch {
241
+ // Expected to fail without sudo
242
+ }
243
+ }
244
+ if (removed > 0) {
245
+ results.push(`ASL logs: ${removed} file(s) cleared`);
246
+ }
247
+ }
248
+ } catch {
249
+ // Cannot access ASL directory without privileges
250
+ }
251
+ }
252
+
253
+ // 4. Clear quarantine events database (download history)
254
+ // This is a SQLite database tracking downloaded files
255
+ const quarantinePath = path.join(homeDir, 'Library', 'Preferences');
256
+ if (fs.existsSync(quarantinePath) && isCommandAvailable('sqlite3')) {
257
+ try {
258
+ const files = fs.readdirSync(quarantinePath);
259
+ const quarantineFiles = files.filter(f => f.startsWith('com.apple.LaunchServices.QuarantineEventsV'));
260
+
261
+ for (const file of quarantineFiles) {
262
+ const dbPath = path.join(quarantinePath, file);
263
+ try {
264
+ execSync(`sqlite3 "${dbPath}" 'delete from LSQuarantineEvent'`, {
265
+ stdio: verbose ? 'inherit' : 'ignore'
266
+ });
267
+ results.push('Quarantine database: cleared');
268
+ } catch {
269
+ // Database may be locked or empty
270
+ if (verbose) {
271
+ console.log(`Could not clear quarantine database: ${dbPath}`);
272
+ }
273
+ }
274
+ }
275
+ } catch {
276
+ // Cannot access quarantine database
277
+ }
278
+ }
279
+
280
+ // Print summary
281
+ console.log('');
282
+ if (results.length > 0) {
283
+ console.log('Summary:');
284
+ for (const result of results) {
285
+ console.log(` - ${result}`);
286
+ }
287
+ } else {
288
+ console.log('Trash is already empty (or requires sudo for remaining items).');
289
+ }
290
+
291
+ console.log('');
292
+ console.log('Tip: For complete cleanup including system files, run with sudo:');
293
+ console.log(' sudo rm -rf /Volumes/*/.Trashes ~/.Trash /private/var/log/asl/*.asl');
294
+ }
295
+
296
+ /**
297
+ * Empty trash on Ubuntu.
298
+ *
299
+ * Ubuntu uses the XDG Trash specification, which stores deleted files in
300
+ * ~/.local/share/Trash/. This directory has three subdirectories:
301
+ * - files/: The actual deleted files
302
+ * - info/: Metadata about each deleted file (original path, deletion time)
303
+ * - expunged/: Files that were permanently deleted from trash
304
+ *
305
+ * The original alias only cleared the files/ directory, but for a complete
306
+ * empty we also clear info/ and expunged/.
307
+ *
308
+ * @param {string[]} args - Command line arguments
309
+ * @returns {Promise<void>}
310
+ */
311
+ async function do_empty_trash_ubuntu(args) {
312
+ // Ubuntu uses XDG trash, which the nodejs implementation handles
313
+ return do_empty_trash_nodejs(args);
314
+ }
315
+
316
+ /**
317
+ * Empty trash on Raspberry Pi OS.
318
+ *
319
+ * Raspberry Pi OS is Debian-based and uses the same XDG Trash specification
320
+ * as Ubuntu. The trash location is ~/.local/share/Trash/.
321
+ *
322
+ * @param {string[]} args - Command line arguments
323
+ * @returns {Promise<void>}
324
+ */
325
+ async function do_empty_trash_raspbian(args) {
326
+ // Raspbian uses XDG trash, same as Ubuntu
327
+ return do_empty_trash_nodejs(args);
328
+ }
329
+
330
+ /**
331
+ * Empty trash on Amazon Linux.
332
+ *
333
+ * Amazon Linux is typically used in server environments where a trash
334
+ * folder may not exist. If a desktop environment is installed, it would
335
+ * use the XDG Trash specification.
336
+ *
337
+ * @param {string[]} args - Command line arguments
338
+ * @returns {Promise<void>}
339
+ */
340
+ async function do_empty_trash_amazon_linux(args) {
341
+ const homeDir = os.getHomeDir();
342
+ const trashPath = path.join(homeDir, '.local', 'share', 'Trash', 'files');
343
+
344
+ // Check if trash directory exists
345
+ if (!fs.existsSync(trashPath)) {
346
+ console.log('No trash folder found.');
347
+ console.log('');
348
+ console.log('On server environments, files deleted with rm are permanently removed.');
349
+ console.log('A trash folder is only created when using a desktop file manager.');
350
+ return;
351
+ }
352
+
353
+ // If trash exists, use the Node.js implementation
354
+ return do_empty_trash_nodejs(args);
355
+ }
356
+
357
+ /**
358
+ * Empty Recycle Bin on Windows using Command Prompt.
359
+ *
360
+ * Windows stores deleted files in the Recycle Bin, which is located at
361
+ * C:\\$Recycle.Bin\\ (a hidden system folder). Each user has their own
362
+ * subfolder identified by their SID.
363
+ *
364
+ * We use PowerShell's Clear-RecycleBin cmdlet, which is the official way
365
+ * to empty the Recycle Bin programmatically.
366
+ *
367
+ * @param {string[]} args - Command line arguments
368
+ * @returns {Promise<void>}
369
+ */
370
+ async function do_empty_trash_cmd(args) {
371
+ const verbose = args.includes('-v') || args.includes('--verbose');
372
+
373
+ console.log('Emptying Recycle Bin...');
374
+
375
+ try {
376
+ // Use PowerShell's Clear-RecycleBin cmdlet
377
+ // The -Force flag skips the confirmation prompt
378
+ // The -ErrorAction SilentlyContinue prevents errors if bin is empty
379
+ execSync(
380
+ 'powershell.exe -NoProfile -Command "Clear-RecycleBin -Force -ErrorAction SilentlyContinue"',
381
+ { stdio: verbose ? 'inherit' : 'ignore' }
382
+ );
383
+ console.log('Recycle Bin emptied successfully.');
384
+ } catch (error) {
385
+ // Try alternative method using Shell.Application COM object
386
+ try {
387
+ execSync(
388
+ 'powershell.exe -NoProfile -Command "$shell = New-Object -ComObject Shell.Application; $shell.NameSpace(10).Items() | ForEach-Object { Remove-Item $_.Path -Force -Recurse -ErrorAction SilentlyContinue }"',
389
+ { stdio: verbose ? 'inherit' : 'ignore' }
390
+ );
391
+ console.log('Recycle Bin emptied successfully.');
392
+ } catch (altError) {
393
+ console.error('Error: Could not empty the Recycle Bin.');
394
+ console.error('You may need to run this command as Administrator.');
395
+ process.exit(1);
396
+ }
397
+ }
398
+ }
399
+
400
+ /**
401
+ * Empty Recycle Bin on Windows using PowerShell.
402
+ *
403
+ * Uses the native Clear-RecycleBin cmdlet which is available in
404
+ * PowerShell 5.0+ (included in Windows 10 and later).
405
+ *
406
+ * @param {string[]} args - Command line arguments
407
+ * @returns {Promise<void>}
408
+ */
409
+ async function do_empty_trash_powershell(args) {
410
+ const verbose = args.includes('-v') || args.includes('--verbose');
411
+
412
+ console.log('Emptying Recycle Bin...');
413
+
414
+ try {
415
+ // Clear-RecycleBin is a native PowerShell cmdlet
416
+ // -Force skips confirmation, -ErrorAction handles empty bin gracefully
417
+ execSync(
418
+ 'Clear-RecycleBin -Force -ErrorAction SilentlyContinue',
419
+ {
420
+ stdio: verbose ? 'inherit' : 'ignore',
421
+ shell: 'powershell.exe'
422
+ }
423
+ );
424
+ console.log('Recycle Bin emptied successfully.');
425
+ } catch (error) {
426
+ console.error('Error: Could not empty the Recycle Bin.');
427
+ console.error('You may need to run PowerShell as Administrator.');
428
+ process.exit(1);
429
+ }
430
+ }
431
+
432
+ /**
433
+ * Empty Recycle Bin from Git Bash on Windows.
434
+ *
435
+ * Git Bash runs on Windows, so we use the Windows Recycle Bin mechanism.
436
+ * We call PowerShell from Git Bash to use the Clear-RecycleBin cmdlet.
437
+ *
438
+ * @param {string[]} args - Command line arguments
439
+ * @returns {Promise<void>}
440
+ */
441
+ async function do_empty_trash_gitbash(args) {
442
+ // Git Bash runs on Windows, use the CMD implementation
443
+ return do_empty_trash_cmd(args);
444
+ }
445
+
446
+ /**
447
+ * Main entry point - detects environment and executes appropriate implementation.
448
+ *
449
+ * The "empty-trash" command empties the system trash/recycle bin and optionally
450
+ * clears system logs to free disk space. This is useful for:
451
+ * - Freeing disk space by permanently deleting trashed files
452
+ * - Clearing download history (macOS quarantine database)
453
+ * - Improving shell startup speed by clearing old system logs
454
+ *
455
+ * Usage:
456
+ * empty-trash # Empty trash with summary output
457
+ * empty-trash -v # Verbose output showing each deleted file
458
+ * empty-trash --verbose # Same as -v
459
+ *
460
+ * @param {string[]} args - Command line arguments
461
+ * @returns {Promise<void>}
462
+ */
463
+ async function do_empty_trash(args) {
464
+ const platform = os.detect();
465
+
466
+ const handlers = {
467
+ 'macos': do_empty_trash_macos,
468
+ 'ubuntu': do_empty_trash_ubuntu,
469
+ 'debian': do_empty_trash_ubuntu,
470
+ 'raspbian': do_empty_trash_raspbian,
471
+ 'amazon_linux': do_empty_trash_amazon_linux,
472
+ 'rhel': do_empty_trash_amazon_linux,
473
+ 'fedora': do_empty_trash_ubuntu,
474
+ 'linux': do_empty_trash_nodejs,
475
+ 'wsl': do_empty_trash_ubuntu,
476
+ 'cmd': do_empty_trash_cmd,
477
+ 'windows': do_empty_trash_cmd,
478
+ 'powershell': do_empty_trash_powershell,
479
+ 'gitbash': do_empty_trash_gitbash
480
+ };
481
+
482
+ const handler = handlers[platform.type];
483
+ if (!handler) {
484
+ console.error(`Platform '${platform.type}' is not supported for this command.`);
485
+ console.error('');
486
+ console.error('Supported platforms:');
487
+ console.error(' - macOS');
488
+ console.error(' - Ubuntu, Debian, and other Linux distributions');
489
+ console.error(' - Raspberry Pi OS');
490
+ console.error(' - Amazon Linux, RHEL, Fedora');
491
+ console.error(' - Windows (CMD, PowerShell, Git Bash)');
492
+ process.exit(1);
493
+ }
494
+
495
+ await handler(args);
17
496
  }
18
497
 
19
- module.exports = { main };
498
+ module.exports = {
499
+ main: do_empty_trash,
500
+ do_empty_trash,
501
+ do_empty_trash_nodejs,
502
+ do_empty_trash_macos,
503
+ do_empty_trash_ubuntu,
504
+ do_empty_trash_raspbian,
505
+ do_empty_trash_amazon_linux,
506
+ do_empty_trash_cmd,
507
+ do_empty_trash_powershell,
508
+ do_empty_trash_gitbash
509
+ };
20
510
 
21
511
  if (require.main === module) {
22
- main(process.argv.slice(2));
512
+ do_empty_trash(process.argv.slice(2));
23
513
  }