Browse Source

'main': The word after 'sudo' is only a non-command word if it is an option.

pull/355/head
Daniel Shahaf 8 years ago
parent
commit
757d047f09
2 changed files with 5 additions and 1 deletions
  1. +3
    -0
      highlighters/main/main-highlighter.zsh
  2. +2
    -1
      highlighters/main/test-data/sudo-command.zsh

+ 3
- 0
highlighters/main/main-highlighter.zsh View File

@ -338,6 +338,9 @@ _zsh_highlight_main_highlighter()
# Parse the sudo command line # Parse the sudo command line
if (( ! in_redirection )); then if (( ! in_redirection )); then
if [[ $this_word == *':sudo_opt:'* ]] && [[ $arg != -* ]]; then
this_word=${this_word//:sudo_opt:/}
fi
if [[ $this_word == *':sudo_opt:'* ]]; then if [[ $this_word == *':sudo_opt:'* ]]; then
case "$arg" in case "$arg" in
# Flag that requires an argument # Flag that requires an argument

+ 2
- 1
highlighters/main/test-data/sudo-command.zsh View File

@ -31,7 +31,7 @@
# * -i (no argument) # * -i (no argument)
# * -C3 (pasted argument) # * -C3 (pasted argument)
# * -u otheruser (non-pasted argument) # * -u otheruser (non-pasted argument)
BUFFER='sudo -C3 -u otheruser -i ls /; sudo ; sudo -u ;'
BUFFER='sudo -C3 -u otheruser -i ls /; sudo ; sudo -u ; sudo notacommand'
expected_region_highlight=( expected_region_highlight=(
"1 4 precommand" # sudo "1 4 precommand" # sudo
@ -43,4 +43,5 @@ expected_region_highlight=(
"29 29 path" # / "29 29 path" # /
"37 37 unknown-token" # ;, error because empty command "37 37 unknown-token" # ;, error because empty command
"47 47 unknown-token" # ;, error because incomplete command "47 47 unknown-token" # ;, error because incomplete command
"54 64 unknown-token" # notacommand - doesn't falls back to "not a command word" codepath
) )

Loading…
Cancel
Save