@@ -147,6 +147,8 @@ _zsh_highlight_main__type() {
147147 # ### $aliases_allowed, on the assumption that aliases are the common case.
148148 integer may_cache=1
149149
150+ local cmd
151+
150152 # Main logic
151153 unset REPLY
152154 if zmodload -e zsh/parameter; then
@@ -165,22 +167,29 @@ _zsh_highlight_main__type() {
165167 REPLY=function
166168 elif (( $+ builtins[$1 ] )) ; then
167169 REPLY=builtin
168- elif (( $+ commands[$1 ] )) ; then
169- REPLY=command
170+ elif [[ $1 != * /* && -x ${cmd::= ${commands[$1]-} } ]]; then
171+ # There is one case where the following logic incorrectly sets REPLY=command
172+ # instead of REPLY=hashed.
173+ #
174+ # % hash zsh=$commands[zsh]
175+ # % zsh # <-- here the type of `zsh` is "command" rather than "hashed"
176+ if [[ $cmd == /(| * /)$1 && $path [(Ie)${cmd: h} ] != 0 ]]; then
177+ REPLY=command
178+ else
179+ REPLY=hashed
180+ fi
170181 # ZSH_VERSION >= 5.1 allows the use of #q. ZSH_VERSION <= 5.8 allows skipping
171182 # 'type -w' calls that are necessary for forward compatibility.
172183 elif [[ $ZSH_VERSION == 5.< 1-8> (| .* ) ]]; then
173- if [[ $1 == * /* && -n $1 (# qN-.*) ||
174- $1 == [^/]* /* && $zsyh_user_options [pathdirs] == on && -n ${^path} /$1 (# q-N.*) ]]; then
175- REPLY=command
176- elif (( _zsh_highlight_main__rehash )) ; then
177- builtin rehash
178- _zsh_highlight_main__rehash=0
179- if (( $+ commands[$1 ] )) ; then
184+ if [[ $1 == * /* ]]; then
185+ if [[ -n $1 (# q-.*N) ||
186+ $1 ! = /* && $zsyh_user_options [pathdirs] == on && -n ${^path} /$1 (# q-.*N) ]]; then
180187 REPLY=command
181188 else
182189 REPLY=none
183190 fi
191+ elif [[ -n ${^path} /$1 (# q-.*N) ]]; then
192+ REPLY=command
184193 else
185194 REPLY=none
186195 fi
@@ -198,6 +207,8 @@ _zsh_highlight_main__type() {
198207 LC_ALL=C builtin type -w -- " $1 " 2>/ dev/ null)##*: } :- none}"
199208 if [[ $REPLY == ' alias' ]]; then
200209 may_cache=0
210+ elif [[ $REPLY == ' hashed' && ( -n $cmd || $1 == * /* ) ]]; then
211+ REPLY=none
201212 fi
202213 fi
203214
@@ -1752,8 +1763,6 @@ _zsh_highlight_main__precmd_hook() {
17521763 _zsh_highlight_main__path_cache=()
17531764 _zsh_highlight_main__arg_cache=()
17541765
1755- _zsh_highlight_main__rehash=1
1756-
17571766 if [[ $ZSH_VERSION != (5.< 9-> * | < 6-> .* ) ]]; then
17581767 _zsh_highlight_main_calculate_styles
17591768 fi
@@ -1763,12 +1772,10 @@ autoload -Uz add-zsh-hook
17631772if add-zsh-hook precmd _zsh_highlight_main__precmd_hook 2> /dev/null; then
17641773 # Initialize caches
17651774 typeset -gA _zsh_highlight_main__command_type_cache _zsh_highlight_main__path_cache _zsh_highlight_main__arg_cache
1766- typeset -gi _zsh_highlight_main__rehash=1
17671775else
17681776 print -r -- >&2 ' zsh-syntax-highlighting: Failed to load add-zsh-hook. Some speed optimizations will not be used.'
17691777 # Make sure the caches are unset
17701778 unset _zsh_highlight_main__command_type_cache _zsh_highlight_main__path_cache _zsh_highlight_main__arg_cache
1771- unset _zsh_highlight_main__rehash
17721779fi
17731780typeset -g a ZSH_HIGHLIGHT_DIRS_BLACKLIST
17741781
@@ -1874,4 +1881,3 @@ _zsh_highlight_main__fallback_of=(
18741881 process-substitution{-delimiter,}
18751882 back-quoted-argument{-delimiter,}
18761883)
1877-
0 commit comments