You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Some characters like dash breaks commands / arguments highlighting #543
I really don’t want to bring whole bash parser/powershell parser into lib.
Is there any other ideas on how to colorise output?
maybe highlight only ${..} part and drop the rest?
I’m with you on not pulling a full bash/PowerShell parser into zx just for log coloring. That feels like a lot of weight for something that should stay lightweight and best-effort.
For this fix I kept the current heuristic approach and made it a bit less eager instead of making it smarter in a parser sense. The bug here was that we were treating + and : as syntax separators universally, which breaks perfectly normal tokens like test:unit, git+ssh://..., and similar argument values. So the change is just to stop classifying those characters as shell syntax and add regression coverage for those cases.
I think that lands in a decent middle ground:
no shell-specific parser
no major behavior change
fewer false positives in common real-world commands
I’d personally keep highlighting for the command word, quotes, $..., and high-confidence operators like |, >, <, ;, &, =. Going all the way down to only ${...} would definitely be safer, but it also gives up a lot of the readability that makes verbose output nice to scan in the first place.
So my thought is: keep it heuristic, but bias toward under-highlighting when we’re unsure. That seems like the best tradeoff for zx.
I took a closer look at this and I think the underlying problem is worth treating as an argument-tokenization/quoting issue rather than as a special case for "-" itself.
The important distinction seems to be between:
characters that are valid inside a single argument,
characters that have shell-level meaning,
and characters that should affect zx's command/argument highlighting or rendering.
Ideally, zx should preserve the original argument boundaries and pass the resulting tokens to the shell without allowing characters such as "-" to change how an argument is classified or displayed.
I’d suggest adding regression coverage around arguments containing:
leading/trailing "-";
"--flag=value";
paths containing "-";
multiple consecutive dashes;
quoted arguments containing "-";
arguments combining "-", spaces, and shell metacharacters.
It would also be useful to assert both the generated command representation and the actual executed argument value. That would help distinguish a formatting/highlighting regression from an actual quoting or execution bug.
If the current implementation is doing its own token/argument parsing for highlighting, centralizing that logic around the same argument representation used for execution could prevent the two paths from diverging.
I’d be happy to put together a minimal regression test first, then use that to narrow down the smallest safe fix.
Hi @antonmedv, I would like to work on this issue.
I can refine the command colorizing regex/lexer to ensure that dashes (-) inside flags (e.g. --flag=value), paths, and kebab-cased tokens are treated as part of the argument rather than splitting the syntax highlighting, without pulling in any heavy external parsers. I will also add regression test cases for dashes in arguments.
Activity
antonmedv commentedon Nov 3, 2022
Yes, my lexer is pretty basic here. Will try to improve.
antonmedv commentedon Nov 17, 2022
I really don’t want to bring whole bash parser/powershell parser into lib.
Is there any other ideas on how to colorise output?
maybe highlight only ${..} part and drop the rest?
tamojit-123 commentedon Apr 25, 2026
I’m with you on not pulling a full bash/PowerShell parser into zx just for log coloring. That feels like a lot of weight for something that should stay lightweight and best-effort.
For this fix I kept the current heuristic approach and made it a bit less eager instead of making it smarter in a parser sense. The bug here was that we were treating + and : as syntax separators universally, which breaks perfectly normal tokens like test:unit, git+ssh://..., and similar argument values. So the change is just to stop classifying those characters as shell syntax and add regression coverage for those cases.
I think that lands in a decent middle ground:
no shell-specific parser
no major behavior change
fewer false positives in common real-world commands
I’d personally keep highlighting for the command word, quotes,
$..., and high-confidence operators like |, >, <, ;, &, =. Going all the way down to only${...}would definitely be safer, but it also gives up a lot of the readability that makes verbose output nice to scan in the first place.So my thought is: keep it heuristic, but bias toward under-highlighting when we’re unsure. That seems like the best tradeoff for zx.
PR : #1459
AryanXCode646 commentedon Sep 25, 2026
I took a closer look at this and I think the underlying problem is worth treating as an argument-tokenization/quoting issue rather than as a special case for "-" itself.
The important distinction seems to be between:
Ideally, zx should preserve the original argument boundaries and pass the resulting tokens to the shell without allowing characters such as "-" to change how an argument is classified or displayed.
I’d suggest adding regression coverage around arguments containing:
It would also be useful to assert both the generated command representation and the actual executed argument value. That would help distinguish a formatting/highlighting regression from an actual quoting or execution bug.
If the current implementation is doing its own token/argument parsing for highlighting, centralizing that logic around the same argument representation used for execution could prevent the two paths from diverging.
I’d be happy to put together a minimal regression test first, then use that to narrow down the smallest safe fix.
abhikashbabu commentedon Oct 27, 2026
Hi @antonmedv, I would like to work on this issue.
I can refine the command colorizing regex/lexer to ensure that dashes (
-) inside flags (e.g.--flag=value), paths, and kebab-cased tokens are treated as part of the argument rather than splitting the syntax highlighting, without pulling in any heavy external parsers. I will also add regression test cases for dashes in arguments.Could you please assign this to me?