Skip to content

fix(tui): stop /shell dropping quotes from the command it runs#44

Merged
ralyodio merged 1 commit into
moshcoder:mainfrom
clawedassistant26:fix/shell-preserves-raw-command-line
Jul 26, 2026
Merged

fix(tui): stop /shell dropping quotes from the command it runs#44
ralyodio merged 1 commit into
moshcoder:mainfrom
clawedassistant26:fix/shell-preserves-raw-command-line

Conversation

@clawedassistant26

Copy link
Copy Markdown
Contributor

The bug

In the mosh pit, /shell <cmd> re-joins the tokenized command line with single spaces before handing it to $SHELL -c:

await openShell(rest.length ? rest.join(" ") : null);

splitCommandLine() has already stripped the user's quotes and escapes at that point, so the shell re-parses the flattened string and splits it again. Any argument containing whitespace silently becomes several arguments.

/shell git commit -m "two words" runs git commit -m two words.

Reproduced on main

$ printf '/shell printf "[%s]\\n" "two words"\n' | node bin/moshcode.mjs
mosh ▸ · bash -c printf [%s]\n two words
[two]n[words]n

Two arguments instead of one, and the escape is gone too. The !cmd escape, which is the same feature, is correct:

$ printf '!printf "[%s]\\n" "two words"\n' | node bin/moshcode.mjs
mosh ▸ · bash -c printf "[%s]\n" "two words"
[two words]

The ! branch already documents why ("we take the raw remainder (not the tokenized parts) so quoting is preserved") — /shell just never got the same treatment.

The fix

src/tui.mjs only: added commandRemainder(line), which returns everything after the first word exactly as typed, and used it for the /shell and /sh branch. Both shell entrypoints now hand the same raw string to $SHELL -c.

Nothing else changes. The tokenized rest is still what native passthroughs like /coinpay and /ugig use — those spawn directly with an argv array, so their quoting was already correct and is untouched.

Tests

Two regression tests in test/tui.test.mjs, both driving the real TUI over stdin:

  • a quoted argument survives /shell as one argument;
  • /shell <cmd> and !<cmd> produce identical output for the same command.

Both fail on main (verified with git stash push -- src/: 6 pass / 2 fail) and pass with the fix. They skip on Windows, which has no POSIX shell for the probe command.

Full suite: node --test155 pass / 0 fail (153 before).

/shell <cmd> re-joined the tokenized command line with spaces before handing
it to $SHELL -c, so every quote and escape the user typed was lost and the
shell re-split the result. `/shell git commit -m "two words"` ran with two
separate arguments; `/shell printf "[%s]\n" "two words"` printed
`[two]n[words]n`.

The !cmd escape already takes the raw remainder of the line for exactly this
reason. Do the same for /shell so both paths behave identically.

Adds two regression tests: one asserting a quoted argument survives, one
asserting /shell and !cmd produce identical output for the same command.
@ralyodio
ralyodio merged commit 05cfd7f into moshcoder:main Jul 26, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants