aboutsummaryrefslogtreecommitdiff
path: root/modules/core/module-fs.js
diff options
context:
space:
mode:
authorAgando <roduccomm@gmail.com>2026-05-27 06:00:43 +0200
committerAgando <roduccomm@gmail.com>2026-05-27 06:00:43 +0200
commit212708b464c2bdbdd9670c00804623dca0729d2c (patch)
treeee190cbb0d1524350baea641df65aa19817744b5 /modules/core/module-fs.js
parentf4d934d341056142da1212c845eeeb170fd452c2 (diff)
auto: 2026-05-27_06:00 changes
Diffstat (limited to 'modules/core/module-fs.js')
-rw-r--r--modules/core/module-fs.js49
1 files changed, 46 insertions, 3 deletions
diff --git a/modules/core/module-fs.js b/modules/core/module-fs.js
index c4bc786..4ba34b0 100644
--- a/modules/core/module-fs.js
+++ b/modules/core/module-fs.js
@@ -5,7 +5,11 @@ class FileSystemModule {
'ls': 'ls [path] [-la] — List files and directories',
'cat': 'cat <file> — Display file contents',
'put': 'put <file> <content> — Create or overwrite a file',
- 'rm': 'rm <file> — Remove a file; use -r/-rf for directories',
+ 'rm': 'rm <file> — Remove a file (moved to trash); use -r/-rf for directories',
+ 'trash': 'trash <file> — Move a file to trash',
+ 'trash-dir': 'trash-dir <dir> — Move a directory to trash',
+ 'ls-trash': 'ls-trash — List items in trash',
+ 'empty-trash': 'empty-trash — Permanently delete all trash items',
'mkdir': 'mkdir <dir> [-p] — Create a directory; -p creates parent paths',
'rmdir': 'rmdir <dir> — Remove a directory',
'mv': 'mv <source> <dest> — Move file or directory',
@@ -80,13 +84,52 @@ class FileSystemModule {
if(!args[0]) return this.terminal.print('Usage: rm <filename>', 'warning');
if(args[0] === '-r' || args[0] === '-rf') {
const t = args[1]; if (!t) return this.terminal.print('Usage: rm -r <dirname>', 'warning');
- if (this.terminal.fs.deleteDirRecursive(t)) this.terminal.print('Removed: ' + t, 'success');
+ // Use trash for recursive dir removal too
+ if (this.terminal.fs.trashDir(t)) this.terminal.print('Moved to trash: ' + t, 'success');
else this.terminal.print('rm: ' + t + ': No such file or directory', 'error');
return;
}
- if(this.terminal.fs.deleteFile(args[0])) this.terminal.print('Removed: ' + args[0], 'success');
+ if(this.terminal.fs.deleteFile(args[0])) this.terminal.print('Moved to trash: ' + args[0], 'success');
else this.terminal.print('rm: ' + args[0] + ': No such file', 'error');
};
+ this.commands['trash'] = (args) => {
+ const fs = this.terminal.fs;
+ if(!args[0]) return this.terminal.print('Usage: trash <filename>', 'warning');
+ const node = fs.readFile(args[0]) !== null ? { type: 'file' } : fs.readDir(args[0]);
+ if (!node) return this.terminal.print('trash: ' + args[0] + ': No such file', 'error');
+ if (node.type === 'dir') {
+ if (fs.trashDir(args[0])) this.terminal.print('Moved to trash: ' + args[0], 'success');
+ else this.terminal.print('trash: ' + args[0] + ': Failed', 'error');
+ } else {
+ const content = fs.readFile(args[0]);
+ if (content !== null) {
+ fs.trashFile(args[0], { type: 'file', content, modified: new Date() });
+ this.terminal.print('Moved to trash: ' + args[0], 'success');
+ } else {
+ this.terminal.print('trash: ' + args[0] + ': No such file', 'error');
+ }
+ }
+ };
+ this.commands['trash-dir'] = (args) => {
+ if(!args[0]) return this.terminal.print('Usage: trash-dir <dirname>', 'warning');
+ if (this.terminal.fs.trashDir(args[0])) this.terminal.print('Moved to trash: ' + args[0], 'success');
+ else this.terminal.print('trash-dir: ' + args[0] + ': No such directory', 'error');
+ };
+ this.commands['ls-trash'] = () => {
+ const fs = this.terminal.fs;
+ const items = fs.listTrash ? fs.listTrash() : [];
+ if (!items.length) return this.terminal.print('Trash is empty', 'info');
+ this.terminal.print('Trash items:', 'info');
+ items.forEach(it => {
+ const date = new Date(it.ts).toLocaleString();
+ this.terminal.print(` ${it.name} [${it.type}] ${date}`);
+ });
+ };
+ this.commands['empty-trash'] = () => {
+ const fs = this.terminal.fs;
+ const removed = fs.emptyTrash ? fs.emptyTrash(0) : 0;
+ this.terminal.print(`Emptied trash: ${removed} item(s) permanently deleted`, removed > 0 ? 'warning' : 'info');
+ };
this.commands['mkdir'] = (args) => {
if(!args[0]) return this.terminal.print('Usage: mkdir <dirname>', 'warning');
if (args[0] === '-p') {