fix(tui): stop /shell dropping quotes from the command it runs#44
Merged
ralyodio merged 1 commit intoJul 26, 2026
Merged
Conversation
/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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The bug
In the mosh pit,
/shell <cmd>re-joins the tokenized command line with single spaces before handing it to$SHELL -c: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"runsgit commit -m two words.Reproduced on main
Two arguments instead of one, and the escape is gone too. The
!cmdescape, which is the same feature, is correct:The
!branch already documents why ("we take the raw remainder (not the tokenized parts) so quoting is preserved") —/shelljust never got the same treatment.The fix
src/tui.mjsonly: addedcommandRemainder(line), which returns everything after the first word exactly as typed, and used it for the/shelland/shbranch. Both shell entrypoints now hand the same raw string to$SHELL -c.Nothing else changes. The tokenized
restis still what native passthroughs like/coinpayand/ugiguse — 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:/shellas 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 --test→ 155 pass / 0 fail (153 before).