diff options
| author | Agando <roduccomm@gmail.com> | 2026-06-01 18:00:38 +0200 |
|---|---|---|
| committer | Agando <roduccomm@gmail.com> | 2026-06-01 18:00:38 +0200 |
| commit | b839e58aa45da1945d0c46c8070b4e7016c59f94 (patch) | |
| tree | d394c7ee9c338e8f449f9f09e53e59f8d41ec5c1 /modules/ext/shell.js | |
| parent | 6aed9c9e0252b0c8f681a358e5a8707271454137 (diff) | |
auto: 2026-06-01_18:00 changes
Diffstat (limited to 'modules/ext/shell.js')
| -rw-r--r-- | modules/ext/shell.js | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/modules/ext/shell.js b/modules/ext/shell.js index 6beb0eb..e87c37c 100644 --- a/modules/ext/shell.js +++ b/modules/ext/shell.js @@ -37,13 +37,28 @@ class ShellModule { // ── Hook into terminal.executeCommand ── init() { - // Wrap executeCommand to add shell parsing + // Guard: prevent double-wrapping if init is called multiple times + if (this._initialized) return; + this._initialized = true; + + // Wrap executeCommand to add shell parsing — only for compound commands const origExecute = this.terminal.executeCommand.bind(this.terminal); const self = this; this.terminal.executeCommand = async function(rawInput) { if (!rawInput.trim()) return; this.markDirty(); - this.print(`webx11@module:~$ ${rawInput}`, 'command-prompt'); + this.printUserPrompt(rawInput); + + // For simple single-word commands without special chars, skip shell parsing + if (/^[a-zA-Z0-9._\/-]+$/.test(rawInput.trim()) && !rawInput.includes(' ') && !rawInput.includes('$')) { + try { + return await this.security.checkAndRun(rawInput); + } catch(e) { + this.print('Error: ' + e.message, 'error'); + return; + } + } + // Substitute variables in the raw input const substituted = self._substituteVars(rawInput); // Split on ; first (sequence) @@ -54,7 +69,7 @@ class ShellModule { const chainParts = self._splitChain(seqPart.trim()); let lastOk = true; for (const chainPart of chainParts) { - if (!chainPart.trim()) continue; + if (!chainPart.cmd.trim()) continue; const { cmd: chainCmd, operator } = chainPart; if (operator === '&&' && !lastOk) continue; if (operator === '||' && lastOk) continue; @@ -74,7 +89,11 @@ class ShellModule { const parts = chainCmd.split(/\s+/); const cmd = parts[0].toLowerCase(); const args = parts.slice(1); - await this.security.checkAndRun(chainCmd); + try { + await this.security.checkAndRun(chainCmd); + } catch(e) { + this.terminal && this.terminal.print ? this.terminal.print('Error: ' + e.message, 'error') : console.error(e); + } } lastOk = true; } |