'main': Restore 0.6.0's behaviour for unknown options.

See discussion on #664.
This commit is contained in:
Daniel Shahaf 2020-01-14 23:06:51 +00:00 committed by Daniel Shahaf
parent 5012d771f3
commit cb166dcc77
3 changed files with 10 additions and 3 deletions

View File

@ -663,8 +663,15 @@ _zsh_highlight_main_highlighter_highlight_list()
next_word+=':sudo_opt:' next_word+=':sudo_opt:'
elif [[ $arg == '-'* ]]; then elif [[ $arg == '-'* ]]; then
# Unknown flag. We don't know whether it takes an argument or not, # 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:' this_word=':sudo_opt:'
next_word+=':start:'
next_word+=':sudo_opt:'
else else
# Not an option flag; nothing to do. (If the command line is # Not an option flag; nothing to do. (If the command line is
# syntactically valid, ${this_word//:sudo_opt:/} should be # syntactically valid, ${this_word//:sudo_opt:/} should be

View File

@ -39,5 +39,5 @@ expected_region_highlight=(
'12 12 commandseparator' # ; '12 12 commandseparator' # ;
'14 17 precommand' # sudo '14 17 precommand' # sudo
'19 20 single-hyphen-option' # -x '19 20 single-hyphen-option' # -x
'22 23 default' # ls '22 23 command' # ls
) )

View File

@ -33,5 +33,5 @@ BUFFER='sudo --askpass ls'
expected_region_highlight=( expected_region_highlight=(
'1 4 precommand' # sudo '1 4 precommand' # sudo
'6 14 double-hyphen-option' # --askpass '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)
) )