Skip to content

fix(chroma/ssh): treat -R and -Q as flags that take an argument - #91

Merged
pschmitt merged 1 commit into
zdharma-continuum:masterfrom
vegerot:fix/ssh-chroma-R-Q-hyphens
Aug 31, 2026
Merged

fix(chroma/ssh): treat -R and -Q as flags that take an argument#91
pschmitt merged 1 commit into
zdharma-continuum:masterfrom
vegerot:fix/ssh-chroma-R-Q-hyphens

Conversation

@vegerot

@vegerot vegerot commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

The bug

→chroma/-ssh.ch keeps a list of ssh flags whose argument must be skipped, so that the argument is not counted as the hostname:

if [[ "$__wrd" = (-b|-c|-D|-E|-e|-F|-I|-i|-J|-L|-l|-m|-O|-o|-p|Q|R|-S|-W|-w) ]]; then
    FAST_HIGHLIGHT[chroma-ssh-skip-two]=1
fi

Every alternative is hyphenated except two — Q and R are written bare — so -Q and -R never match:

-R  -> NO MATCH  (argument treated as hostname)
-L  -> skip-two SET
-p  -> skip-two SET
R   -> skip-two SET   # matches a literal `R`, which is not an ssh flag

What you see

ssh -R 5037:localhost:5037 devbox

skip-two is never set, so 5037:localhost:5037 is counted as the first non-option token and becomes the hostname. Its trailing :5037 then matches the host:port check on line 106, and line 143 calls zle -M:

Format of hostname incorrect, use -p to pass port number

That appears while typing, on a completely valid command line, and the forward spec is coloured as a bad host.

-L is in the list correctly, so the identical local forward highlights fine — only -R trips it. -Q mislabels its argument as the host in the same way, though it does not reach the message.

The fix

Two hyphens: |-p|Q|R|-S||-p|-Q|-R|-S|.

Tests

Two added to tests/main.zunit:

  • ssh -R 5037:localhost:5037 devbox must produce no message — fails on master, passes with this change.
  • ssh devbox:22 must still produce the message — passes both ways, so the feature itself is unchanged.

Chromas are autoloaded functions, so @setup now adds the repo to fpath and autoloads the ssh chroma, the way the plugin file does at startup.

11 tests run
Passed 11 / Failed 0     # with this change
Passed 10 / Failed 1     # chroma reverted, tests kept

Verified on zsh 5.9, macOS arm64, with the zunit revision the CI workflow pins.

Related

#33 reports -LRD forwarding specs highlighting incorrectly. This fixes the -R half of it; the request there for colouring the components of a forward spec is separate and not addressed here.

The ssh chroma keeps a list of flags whose argument must be skipped, so the
argument is not mistaken for the hostname. Every entry is hyphenated except
two: `Q` and `R` are written bare, so `-Q` and `-R` never match.

For `-R` the consequence is visible. Typing

    ssh -R 5037:localhost:5037 devbox

leaves `5037:localhost:5037` counted as the first non-option token, so it
becomes the hostname. Its trailing `:5037` then matches the host:port check and
the chroma calls `zle -M` with

    Format of hostname incorrect, use -p to pass port number

while you type, on a command line that is perfectly valid. `-L` is in the list
correctly, so the identical local-forward spec highlights fine and only the
remote forward is affected. `-Q` mislabels its argument as the host in the same
way, without reaching the message.

Adds two tests: `-R` must stay silent, and a hostspec that really does carry a
port must still be reported.

Related to zdharma-continuum#33, which reports `-LRD` forwarding specs highlighting wrongly;
this fixes the `-R` half.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@pschmitt
pschmitt merged commit 4672ad5 into zdharma-continuum:master Aug 31, 2026
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