@@ -157,6 +157,16 @@ _zsh_highlight_main_calculate_fallback() {
157
157
#
158
158
# The result will be stored in REPLY.
159
159
_zsh_highlight_main__type () {
160
+ # Cache lookup
161
+ if (( $+ _zsh_highlight_main__command_type_cache )) ; then
162
+ REPLY=$_zsh_highlight_main__command_type_cache [$1 ]
163
+ if [[ -n " $REPLY " ]]; then
164
+ REPLY[-1]=
165
+ [[ -n $REPLY ]]
166
+ return
167
+ fi
168
+ fi
169
+
160
170
integer -r aliases_allowed=${2-1}
161
171
# We won't cache replies of anything that exists as an alias at all, to
162
172
# ensure the cached value is correct regardless of $aliases_allowed.
@@ -165,36 +175,28 @@ _zsh_highlight_main__type() {
165
175
# ### $aliases_allowed, on the assumption that aliases are the common case.
166
176
integer may_cache=1
167
177
168
- # Cache lookup
169
- if (( $+ _zsh_highlight_main__command_type_cache )) ; then
170
- REPLY=$_zsh_highlight_main__command_type_cache [(e)$1 ]
171
- if [[ -n " $REPLY " ]]; then
172
- return
173
- fi
174
- fi
175
-
176
178
# Main logic
177
179
if (( $# options_to_set )) ; then
178
180
setopt localoptions $options_to_set ;
179
181
fi
180
182
unset REPLY
181
183
if zmodload -e zsh/parameter; then
182
- if (( $+ aliases[(e) $1 ] )) ; then
184
+ if (( $+ aliases[$1 ] )) ; then
183
185
may_cache=0
184
186
fi
185
- if (( ${+galiases[(e) $1]} )) && (( aliases_allowed )) ; then
187
+ if (( ${+galiases[$1]} )) && (( aliases_allowed )) ; then
186
188
REPLY=' global alias'
187
- elif (( $+ aliases[(e) $1 ] )) && (( aliases_allowed )) ; then
189
+ elif (( $+ aliases[$1 ] )) && (( aliases_allowed )) ; then
188
190
REPLY=alias
189
- elif [[ $1 == * .* && -n ${1% .* } ]] && (( $+ saliases[(e) ${1##* .} ] )) ; then
191
+ elif [[ $1 == * .* && -n ${1% .* } ]] && (( $+ saliases[${1##* .} ] )) ; then
190
192
REPLY=' suffix alias'
191
193
elif (( $reswords [(Ie)$1 ] )) ; then
192
194
REPLY=reserved
193
- elif (( $+ functions[(e) $1 ] )) ; then
195
+ elif (( $+ functions[$1 ] )) ; then
194
196
REPLY=function
195
- elif (( $+ builtins[(e) $1 ] )) ; then
197
+ elif (( $+ builtins[$1 ] )) ; then
196
198
REPLY=builtin
197
- elif (( $+ commands[(e) $1 ] )) ; then
199
+ elif (( $+ commands[$1 ] )) ; then
198
200
REPLY=command
199
201
# None of the special hashes had a match, so fall back to 'type -w', for
200
202
# forward compatibility with future versions of zsh that may add new command
@@ -206,6 +208,12 @@ _zsh_highlight_main__type() {
206
208
# falling through to the $() below, incurring a fork. (Issue #354.)
207
209
#
208
210
# The first disjunct mimics the isrelative() C call from the zsh bug.
211
+ elif [[ $1 == * /* || $ZSH_VERSION != (5.< 9-> * | < 6-> .* ) ]]; then
212
+ if [[ -n $1 (# qN.*) || -o path_dirs && -n ${^path}/$1(#qN.*) ]]; then
213
+ REPLY=command
214
+ else
215
+ REPLY=none
216
+ fi
209
217
elif { [[ $1 != * /* ]] || is-at-least 5.3 } &&
210
218
# Add a subshell to avoid a zsh upstream bug; see issue #606.
211
219
# ### Remove the subshell when we stop supporting zsh 5.7.1 (I assume 5.8 will have the bugfix).
@@ -231,11 +239,10 @@ _zsh_highlight_main__type() {
231
239
fi
232
240
233
241
# Cache population
234
- if (( may_cache )) && (( $+ _zsh_highlight_main__command_type_cache )) ; then
235
- _zsh_highlight_main__command_type_cache[(e) $1 ]=$REPLY
242
+ if (( may_cache && $+ _zsh_highlight_main__command_type_cache )) ; then
243
+ _zsh_highlight_main__command_type_cache[$1 ]=$REPLY .
236
244
fi
237
245
[[ -n $REPLY ]]
238
- return $?
239
246
}
240
247
241
248
# Checks whether $1 is something that can be run.
@@ -1241,7 +1248,7 @@ _zsh_highlight_main_highlighter_check_path()
1241
1248
fi
1242
1249
return 0
1243
1250
elif [[ ! -d $expanded_path ]]; then
1244
- # ### This seems unreachable for the current callers
1251
+ REPLY=command
1245
1252
return 0
1246
1253
fi
1247
1254
fi
0 commit comments