fix(chroma/ssh): treat -R and -Q as flags that take an argument (#91)
Some checks failed
zunit / zunit (push) Has been cancelled

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 #33, which reports `-LRD` forwarding specs highlighting wrongly;
this fixes the `-R` half.

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Max Coplan 2026-08-31 00:14:04 -07:00 committed by GitHub
parent 3d574ccf48
commit 4672ad5dd9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 25 additions and 1 deletions

View file

@ -3,6 +3,9 @@
load "../fast-highlight"
setopt interactive_comments
-fast-highlight-fill-option-variables
# Chromas are autoloaded functions; the plugin file does this at startup.
fpath+=( "$PWD" )
autoload -Uz -- '→chroma/-ssh.ch'
}
@test 'ls /usr/bin' {
@ -121,4 +124,25 @@ reply=()
assert "$reply[9]" same_as ""
}
@test 'ssh -R 5037:localhost:5037 devbox' {
reply=()
PREBUFFER=""
BUFFER="ssh -R 5037:localhost:5037 devbox"
evl -fast-highlight-process "$PREBUFFER" "$BUFFER" 0
# -R takes an argument, so the forward spec is not the hostname and its
# trailing :5037 is not a port passed to a hostspec.
assert "${FAST_HIGHLIGHT[chroma-ssh-message]}" same_as ""
}
@test 'ssh devbox:22' {
reply=()
PREBUFFER=""
BUFFER="ssh devbox:22"
evl -fast-highlight-process "$PREBUFFER" "$BUFFER" 0
# A port really passed in the hostspec is still reported.
assert "${FAST_HIGHLIGHT[chroma-ssh-message]}" same_as "Format of hostname incorrect, use -p to pass port number"
}
# vim:ft=zsh:sw=4:sts=4:et

View file

@ -51,7 +51,7 @@ local -a match mbegin mend completions_users completions_host
# Detected option, add style for it.
[[ "$__wrd" = --* ]] && __style=${FAST_THEME_NAME}double-hyphen-option || \
__style=${FAST_THEME_NAME}single-hyphen-option
if [[ "$__wrd" = (-b|-c|-D|-E|-e|-F|-I|-i|-J|-L|-l|-m|-O|-o|-p|Q|R|-S|-W|-w) ]]; then
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
else