From 26a82113b08b131446193d8b52f30a8946814c6a Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sat, 25 Nov 2017 01:25:07 +0000 Subject: [PATCH] 'main': Highlight 'sudo' correctly when it's not installed. No test because _zsh_highlight_main__type() falls back to 'type -w' which runs 'rehash' implicitly, so on systems where 'sudo' is installed it's not possible to simulate its being absent. Test by forcing _zsh_highlight_main__type() to return 'none' when the argument is [[ $1 == 'sudo' ]], and: (1) Run 'make test' and confirm that all tests either pass, or fail and the first test point that fails is one that expects "sudo" at command position to be highlighted as 'command'; (2) In an interactive zsh, 'sudo' at command position is highlighted as an error. --- highlighters/main/main-highlighter.zsh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 7850ddc..346b754 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -147,6 +147,7 @@ _zsh_highlight_main__type() { fi fi if ! (( $+REPLY )); then + # Note that 'type -w' will run 'rehash' implicitly. REPLY="${$(LC_ALL=C builtin type -w -- $1 2>/dev/null)##*: }" fi if (( $+_zsh_highlight_main__command_type_cache )); then @@ -457,7 +458,7 @@ _zsh_highlight_highlighter_main_paint() 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" ]]; then + elif [[ "$arg" = "sudo" ]] && { _zsh_highlight_main__type sudo; [[ -n $REPLY && $REPLY != "none" ]] }; then style=precommand next_word=${next_word//:regular:/} next_word+=':sudo_opt:'