diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 9ac15e9..038215d 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -663,8 +663,15 @@ _zsh_highlight_main_highlighter_highlight_list() next_word+=':sudo_opt:' elif [[ $arg == '-'* ]]; then # Unknown flag. We don't know whether it takes an argument or not, - # so we don't modify $next_word. + # so modify $next_word as we do for flags that require no argument. + # With that behaviour, if the flag in fact takes no argument we'll + # highlight the inner command word correctly, and if it does take an + # argument we'll highlight the command word correctly if the argument + # was given in the same shell word as the flag (as in '-uphy1729' or + # '--user=phy1729' without spaces). this_word=':sudo_opt:' + next_word+=':start:' + next_word+=':sudo_opt:' else # Not an option flag; nothing to do. (If the command line is # syntactically valid, ${this_word//:sudo_opt:/} should be diff --git a/highlighters/main/test-data/precommand-unknown-option.zsh b/highlighters/main/test-data/precommand-unknown-option.zsh index cd94233..6baf9ff 100644 --- a/highlighters/main/test-data/precommand-unknown-option.zsh +++ b/highlighters/main/test-data/precommand-unknown-option.zsh @@ -39,5 +39,5 @@ expected_region_highlight=( '12 12 commandseparator' # ; '14 17 precommand' # sudo '19 20 single-hyphen-option' # -x - '22 23 default' # ls + '22 23 command' # ls ) diff --git a/highlighters/main/test-data/sudo-longopt.zsh b/highlighters/main/test-data/sudo-longopt.zsh index 7a2ea9d..697f555 100644 --- a/highlighters/main/test-data/sudo-longopt.zsh +++ b/highlighters/main/test-data/sudo-longopt.zsh @@ -33,5 +33,5 @@ BUFFER='sudo --askpass ls' expected_region_highlight=( '1 4 precommand' # sudo '6 14 double-hyphen-option' # --askpass - '16 17 default' # ls (we don't know whether --askpass takes an argument) + '16 17 command' # ls (we don't know whether --askpass takes an argument) )