aboutsummaryrefslogtreecommitdiff
path: root/modules/ext/alias.js
diff options
context:
space:
mode:
Diffstat (limited to 'modules/ext/alias.js')
-rw-r--r--modules/ext/alias.js26
1 files changed, 18 insertions, 8 deletions
diff --git a/modules/ext/alias.js b/modules/ext/alias.js
index 80663ac..06a5d47 100644
--- a/modules/ext/alias.js
+++ b/modules/ext/alias.js
@@ -3,8 +3,10 @@ class AliasModule {
this.commands = {};
this.terminal = null;
this.key = 'webx11_aliases';
- this.defaults = { 'll': 'ls', 'h': 'help', 'cls': 'clear' };
+ this.defaults = { 'll': 'ls', 'h': 'help', 'cls': 'clear', 'sh': 'script' };
this.aliases = this.load();
+ this._aliasDepth = 0;
+ this._aliasMaxDepth = 10;
}
getHelpInfo() {
@@ -37,7 +39,10 @@ class AliasModule {
if (name === 'alias' || name === 'unalias') return;
const target = this.aliases[name];
this.commands[name] = (args) => {
- this.terminal.executeCommand(target + (args.length ? ' ' + args.join(' ') : ''));
+ if (this._aliasDepth >= this._aliasMaxDepth) { this.terminal.print(`alias: max depth (${this._aliasMaxDepth}) reached`, 'error'); return; }
+ this._aliasDepth++;
+ try { this.terminal.executeCommand(target + (args.length ? ' ' + args.join(' ') : '')); }
+ finally { this._aliasDepth--; }
};
});
}
@@ -64,7 +69,8 @@ class AliasModule {
// Show specific alias value
const name = args[0];
if (this.aliases[name]) {
- this.terminal.print(`${name}=${this.aliases[name]}`, 'info');
+ const mark = this.defaults[name] ? ' (built-in)' : '';
+ this.terminal.print(`${name}=${this.aliases[name]}${mark}`, 'info');
} else {
this.terminal.print(`Alias '${name}' not found`, 'error');
}
@@ -77,15 +83,19 @@ class AliasModule {
if (name === 'alias' || name === 'unalias') {
return this.terminal.print('Cannot alias reserved command name', 'error');
}
+ if (this.defaults[name]) {
+ return this.terminal.print(`Cannot alias built-in alias '${name}'`, 'warning');
+ }
this.aliases[name] = value;
this.save();
// Register the new alias as a command immediately
- if (!this.defaults[name]) {
- const target = value;
- this.commands[name] = (args) => {
- this.terminal.executeCommand(target + (args.length ? ' ' + args.join(' ') : ''));
+ const target = value;
+ this.commands[name] = (args) => {
+ if (this._aliasDepth >= this._aliasMaxDepth) { this.terminal.print(`alias: max depth (${this._aliasMaxDepth}) reached`, 'error'); return; }
+ this._aliasDepth++;
+ try { this.terminal.executeCommand(target + (args.length ? ' ' + args.join(' ') : '')); }
+ finally { this._aliasDepth--; }
};
- }
this.terminal.print(`Alias set: ${name}=${value}`, 'success');
}
handleUnalias(args) {