From 06710f37807ad9095e7e159e2215b1710368ca96 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 4 May 2020 18:35:15 +0000 Subject: [PATCH] 'main': Don't run `_zsh_highlight_main__type` on every non-command word. Fixes #728, the performance regression from 0.7.1. --- highlighters/main/main-highlighter.zsh | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 4010648..66a3d2a 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -273,6 +273,18 @@ _zsh_highlight_main__resolve_alias() { fi } +# Return true iff $1 is a global alias +_zsh_highlight_main__is_global_alias() { + if zmodload -e zsh/parameter; then + (( ${+galiases[$arg]} )) + elif [[ $arg == '='* ]]; then + # avoid running into «alias -L '=foo'» erroring out with 'bad assignment' + return 1 + else + alias -L -g -- "$1" >/dev/null + fi +} + # Check that the top of $braces_stack has the expected value. If it does, set # the style according to $2; otherwise, set style=unknown-token. # @@ -1061,7 +1073,7 @@ _zsh_highlight_main_highlighter_highlight_list() if [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_CONTROL_FLOW:#"$arg"} ]]; then next_word=':start::start_of_pipeline:' fi - elif _zsh_highlight_main__type "$arg"; [[ $REPLY == 'global alias' ]]; then # $arg is a global alias that isn't in command position + elif _zsh_highlight_main__is_global_alias "$arg"; then # $arg is a global alias that isn't in command position style=global-alias else # $arg is a non-command word case $arg in