'main': Make sudo handling more generic.

Part of issue #343.
This commit is contained in:
Daniel Shahaf 2016-07-28 07:37:59 +00:00 committed by Matthew Martin
parent dbdebfaaa5
commit 6e8984e2ec

View file

@ -235,6 +235,16 @@ _zsh_highlight_highlighter_main_paint()
local -a options_to_set reply # used in callees
local REPLY
# $flags_with_argument is a set of letters, corresponding to the option letters
# that would be followed by a colon in a getopts specification.
local flags_with_argument
# $precommand_options maps precommand name to value of $flags_with_argument
# for that precommand.
local -A precommand_options
precommand_options=(
'sudo' Cgprtu
)
if [[ $zsyh_user_options[ignorebraces] == on || ${zsyh_user_options[ignoreclosebraces]:-off} == on ]]; then
local right_brace_is_recognised_everywhere=false
else
@ -537,7 +547,8 @@ _zsh_highlight_main_highlighter_highlight_list()
if [[ $this_word == *':sudo_opt:'* ]]; then
case "$arg" in
# Flag that requires an argument
'-'[Cgprtu]) this_word=${this_word//:start:/};
'-'[$flags_with_argument])
this_word=${this_word//:start:/};
next_word=':sudo_arg:';;
# This prevents misbehavior with sudo -u -otherargument
'-'*) this_word=${this_word//:start:/};
@ -559,8 +570,9 @@ _zsh_highlight_main_highlighter_highlight_list()
elif [[ $this_word == *':start:'* ]] && (( in_redirection == 0 )); then # $arg is the command word
if [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS:#"$arg"} ]]; then
style=precommand
elif [[ "$arg" = "sudo" ]] && { _zsh_highlight_main__type sudo; [[ -n $REPLY && $REPLY != "none" ]] }; then
elif (( ${+precommand_options[$arg]} )) && { _zsh_highlight_main__type $arg; [[ -n $REPLY && $REPLY != "none" ]] }; then
style=precommand
flags_with_argument=${precommand_options[$arg]}
next_word=${next_word//:regular:/}
next_word+=':sudo_opt:'
next_word+=':start:'