From 4672ad5dd9ad68a7effc1476d65afb7c584ce2b3 Mon Sep 17 00:00:00 2001 From: Max Coplan Date: Mon, 31 Aug 2026 00:14:04 -0700 Subject: [PATCH] fix(chroma/ssh): treat -R and -Q as flags that take an argument (#91) 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) --- tests/main.zunit | 24 ++++++++++++++++++++++++ →chroma/-ssh.ch | 2 +- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/tests/main.zunit b/tests/main.zunit index 110f34c..42b91f0 100644 --- a/tests/main.zunit +++ b/tests/main.zunit @@ -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 diff --git a/→chroma/-ssh.ch b/→chroma/-ssh.ch index 1d5e257..cd48e84 100644 --- a/→chroma/-ssh.ch +++ b/→chroma/-ssh.ch @@ -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