@@ -99,7 +99,8 @@ _zsh_highlight_main_calculate_styles() {
99
99
local config=" ${(pj: \0 : )${(@ kv)ZSH_HIGHLIGHT_STYLES} } " .
100
100
[[ $config == $_zsh_highlight_main__config ]] && return
101
101
_zsh_highlight_main__config=$config
102
- typeset -gA _zsh_highlight_main__styles=(" ${(@ kv)ZSH_HIGHLIGHT_STYLES} " )
102
+ typeset -gA _zsh_highlight_main__styles
103
+ _zsh_highlight_main__styles=(" ${(@ kv)ZSH_HIGHLIGHT_STYLES} " )
103
104
104
105
integer finished
105
106
local key val
@@ -131,16 +132,11 @@ _zsh_highlight_main_calculate_fallback() {
131
132
#
132
133
# If $2 is 0, do not consider aliases.
133
134
#
134
- # The result will be stored in REPLY.
135
+ # The result will be stored in REPLY. It's guaranteed to be non-empty.
135
136
_zsh_highlight_main__type () {
136
137
# Cache lookup
137
138
if (( $+ _zsh_highlight_main__command_type_cache )) ; then
138
- REPLY=$_zsh_highlight_main__command_type_cache [$1 ]
139
- if [[ -n " $REPLY " ]]; then
140
- REPLY[-1]=
141
- [[ -n $REPLY ]]
142
- return
143
- fi
139
+ [[ -n ${REPLY::= $_zsh_highlight_main__command_type_cache [$1]} ]] && return
144
140
fi
145
141
146
142
integer -r aliases_allowed=${2-1}
@@ -152,9 +148,6 @@ _zsh_highlight_main__type() {
152
148
integer may_cache=1
153
149
154
150
# Main logic
155
- if (( $# options_to_set )) ; then
156
- setopt localoptions $options_to_set ;
157
- fi
158
151
unset REPLY
159
152
if zmodload -e zsh/parameter; then
160
153
if (( $+ aliases[$1 ] )) ; then
@@ -174,62 +167,44 @@ _zsh_highlight_main__type() {
174
167
REPLY=builtin
175
168
elif (( $+ commands[$1 ] )) ; then
176
169
REPLY=command
177
- # None of the special hashes had a match, so fall back to 'type -w', for
178
- # forward compatibility with future versions of zsh that may add new command
179
- # types.
180
- #
181
- # zsh 5.2 and older have a bug whereby running 'type -w ./sudo' implicitly
182
- # runs 'hash ./sudo=/usr/local/bin/./sudo' (assuming /usr/local/bin/sudo
183
- # exists and is in $PATH). Avoid triggering the bug, at the expense of
184
- # falling through to the $() below, incurring a fork. (Issue #354.)
185
- #
186
- # The first disjunct mimics the isrelative() C call from the zsh bug.
187
- elif [[ $1 == * /* || $ZSH_VERSION != (5.< 9-> * | < 6-> .* ) ]]; then
188
- if [[ -n $1 (# qN.*) || -o path_dirs && -n ${^path}/$1(#qN.*) ]]; then
170
+ # ZSH_VERSION >= 5.1 allows the use of #q. ZSH_VERSION <= 5.8 allows skipping
171
+ # 'type -w' calls that are necessary for forward compatibility.
172
+ elif [[ $ZSH_VERSION == 5.< 1-8> (| .* ) ]]; then
173
+ if [[ -n $1 (# qN-.*) ||
174
+ $1 == [^/]* /* && $zsyh_user_options [pathdirs] == on && -n ${^path} /$1 (# q-N.*) ]]; then
189
175
REPLY=command
190
176
else
191
177
REPLY=none
192
178
fi
193
- elif { [[ $1 != * /* ]] || is-at-least 5.3 } &&
194
- # Add a subshell to avoid a zsh upstream bug; see issue #606.
195
- # ### Remove the subshell when we stop supporting zsh 5.7.1 (I assume 5.8 will have the bugfix).
196
- ! (builtin type -w -- " $1 " ) > /dev/null 2>&1 ; then
197
- REPLY=none
198
179
fi
199
180
fi
200
- if ! (( $+ REPLY )) ; then
181
+ if (( ! $+ REPLY )) ; then
201
182
# zsh/parameter not available or had no matches.
202
183
#
203
184
# Note that 'type -w' will run 'rehash' implicitly.
204
185
#
205
186
# We 'unalias' in a subshell, so the parent shell is not affected.
206
- #
207
- # The colon command is there just to avoid a command substitution that
208
- # starts with an arithmetic expression [«((…))» as the first thing inside
209
- # «$(…)»], which is area that has had some parsing bugs before 5.6
210
- # (approximately).
211
- REPLY=" ${$(: ; (( aliases_allowed )) || unalias -- " $1 " 2>/ dev/ null; LC_ALL=C builtin type -w -- " $1 " 2>/ dev/ null)##*: } "
187
+ REPLY=" ${${$(
188
+ [[ $zsyh_user_options[pathdirs] == on ]] && setopt pathdirs
189
+ (( aliases_allowed )) || unalias -- " $1 " 2>/ dev/ null
190
+ LC_ALL=C builtin type -w -- " $1 " 2>/ dev/ null)##*: } :- none}"
212
191
if [[ $REPLY == ' alias' ]]; then
213
192
may_cache=0
214
193
fi
215
194
fi
216
195
217
196
# Cache population
218
197
if (( may_cache && $+ _zsh_highlight_main__command_type_cache )) ; then
219
- _zsh_highlight_main__command_type_cache[$1 ]=$REPLY .
198
+ _zsh_highlight_main__command_type_cache[$1 ]=$REPLY
220
199
fi
221
- [[ -n $REPLY ]]
222
200
}
223
201
224
202
# Checks whether $1 is something that can be run.
225
203
#
226
- # Return 0 if runnable, 1 if not runnable, 2 if trouble .
204
+ # Return 0 if runnable, 1 if not runnable.
227
205
_zsh_highlight_main__is_runnable () {
228
- if _zsh_highlight_main__type " $1 " ; then
229
- [[ $REPLY != none ]]
230
- else
231
- return 2
232
- fi
206
+ _zsh_highlight_main__type " $1 "
207
+ [[ $REPLY != none ]]
233
208
}
234
209
235
210
# Check whether the first argument is a redirection operator token.
@@ -301,7 +276,7 @@ _zsh_highlight_highlighter_main_paint()
301
276
return
302
277
fi
303
278
304
- local -a options_to_set reply # used in callees
279
+ local -a reply # used in callees
305
280
local REPLY
306
281
307
282
# $flags_with_argument is a set of letters, corresponding to the option letters
@@ -327,10 +302,6 @@ _zsh_highlight_highlighter_main_paint()
327
302
local -i right_brace_is_recognised_everywhere=1
328
303
fi
329
304
330
- if [[ $zsyh_user_options [pathdirs] == on ]]; then
331
- options_to_set+=( PATH_DIRS )
332
- fi
333
-
334
305
if (( $+ X_ZSH_HIGHLIGHT_DIRS_BLACKLIST )) ; then
335
306
print >&2 ' zsh-syntax-highlighting: X_ZSH_HIGHLIGHT_DIRS_BLACKLIST is deprecated. Please use ZSH_HIGHLIGHT_DIRS_BLACKLIST.'
336
307
ZSH_HIGHLIGHT_DIRS_BLACKLIST=($X_ZSH_HIGHLIGHT_DIRS_BLACKLIST )
@@ -1227,7 +1198,8 @@ _zsh_highlight_main_highlighter_highlight_argument()
1227
1198
{
1228
1199
if (( $+ _zsh_highlight_main__arg_cache )) ; then
1229
1200
local cache_key=$1 $' \0' $2 $' \0' $arg $' \0' $last_arg $' \0' $has_end $' \0' $highlight_glob $' \0' $in_redirection $' \0' $zsyh_user_options [multios]
1230
- local -a cache_val=(${(@ 0)_zsh_highlight_main__arg_cache[$cache_key]} )
1201
+ local -a cache_val
1202
+ cache_val=(${(@ 0)_zsh_highlight_main__arg_cache[$cache_key]} )
1231
1203
if (( $# cache_val )) ; then
1232
1204
integer offset=$(( start_pos - $cache_val [- 1 ] ))
1233
1205
local start end_ style
@@ -1788,7 +1760,8 @@ else
1788
1760
fi
1789
1761
typeset -g a ZSH_HIGHLIGHT_DIRS_BLACKLIST
1790
1762
1791
- typeset -g A _zsh_highlight_main__precommand_options= (
1763
+ typeset -g A _zsh_highlight_main__precommand_options
1764
+ _zsh_highlight_main__precommand_options= (
1792
1765
# Precommand modifiers as of zsh 5.6.2 cf. zshmisc(1).
1793
1766
' -' ' '
1794
1767
' builtin' ' '
@@ -1825,7 +1798,8 @@ typeset -gA _zsh_highlight_main__precommand_options=(
1825
1798
# flock
1826
1799
# ssh
1827
1800
1828
- typeset -g a _zsh_highlight_main__tokens_commandseparator= (
1801
+ typeset -g a _zsh_highlight_main__tokens_commandseparator
1802
+ _zsh_highlight_main__tokens_commandseparator= (
1829
1803
' |' ' ||' ' ;' ' &' ' &&'
1830
1804
$' \n ' # ${(z)} returns ';' but we convert it to $'\n'
1831
1805
' |&'
@@ -1836,7 +1810,8 @@ typeset -ga _zsh_highlight_main__tokens_commandseparator=(
1836
1810
1837
1811
# Tokens that, at (naively-determined) "command position", are followed by
1838
1812
# a de jure command position. All of these are reserved words.
1839
- typeset -g a _zsh_highlight_main__tokens_control_flow= (
1813
+ typeset -g a _zsh_highlight_main__tokens_control_flow
1814
+ _zsh_highlight_main__tokens_control_flow= (
1840
1815
$' \x7b ' # block
1841
1816
$' \x28 ' # subshell
1842
1817
' ()' # anonymous function
@@ -1852,7 +1827,8 @@ typeset -ga _zsh_highlight_main__tokens_control_flow=(
1852
1827
' !' # reserved word; unrelated to $histchars[1]
1853
1828
)
1854
1829
1855
- typeset -g A _zsh_highlight_main__fallback_of= (
1830
+ typeset -g A _zsh_highlight_main__fallback_of
1831
+ _zsh_highlight_main__fallback_of= (
1856
1832
alias arg0
1857
1833
suffix-alias arg0
1858
1834
global-alias dollar-double-quoted-argument
0 commit comments