main: Highlight unknown precommand option as unknown-token

This commit is contained in:
Matthew Martin
2018-10-09 22:51:54 -05:00
parent c6e3d216ec
commit e27e53b1ef
2 changed files with 58 additions and 3 deletions

View File

@@ -612,12 +612,24 @@ _zsh_highlight_main_highlighter_highlight_list()
# Flag that requires an argument
this_word=${this_word//:start:/}
next_word=':sudo_arg:'
elif [[ $arg == '-'* ]]; then
# Flag that requires no argument, or unknown flag.
# This prevents misbehavior with sudo -u -otherargument
elif [[ -n $flags_with_argument ]] &&
[[ $arg == '-'[$flags_sans_argument]#[$flags_with_argument]* ]]; then
# Argument attached in the same word
this_word=${this_word//:start:/}
next_word+=':start:'
next_word+=':sudo_opt:'
elif [[ $arg == '-'[$flags_sans_argument]# ]]; then
# Flag that requires no argument
this_word=:sudo_opt:
next_word+=':start:'
next_word+=':sudo_opt:'
elif [[ $arg == '-'* ]]; then
# Unknown flag
this_word=:sudo_opt:
next_word+=':start:'
next_word+=':sudo_opt:'
_zsh_highlight_main_add_region_highlight $start_pos $end_pos unknown-token
continue
else
# Not an option flag; nothing to do. (If the command line is
# syntactically valid, ${this_word//:sudo_opt:/} should be