@@ -1006,7 +1006,7 @@ _zsh_highlight_main_highlighter_highlight_list()
1006
1006
fi
1007
1007
_zsh_highlight_main__stack_pop ' R' reserved-word
1008
1008
else
1009
- if _zsh_highlight_main_highlighter_check_path $arg ; then
1009
+ if _zsh_highlight_main_highlighter_check_path $arg 1 ; then
1010
1010
style=$REPLY
1011
1011
else
1012
1012
style=unknown-token
@@ -1115,12 +1115,19 @@ _zsh_highlight_main_highlighter_highlight_path_separators()
1115
1115
# Check if $1 is a path.
1116
1116
# If yes, return 0 and in $REPLY the style to use.
1117
1117
# Else, return non-zero (and the contents of $REPLY is undefined).
1118
+ #
1119
+ # $2 should be non-zero iff we're in command position.
1118
1120
_zsh_highlight_main_highlighter_check_path ()
1119
1121
{
1120
1122
_zsh_highlight_main_highlighter_expand_path " $1 "
1121
1123
local expanded_path=" $REPLY " tmp_path
1124
+ integer in_command_position=$2
1122
1125
1123
- REPLY=path
1126
+ if (( in_command_position )) ; then
1127
+ REPLY=arg0
1128
+ else
1129
+ REPLY=path
1130
+ fi
1124
1131
1125
1132
if [[ ${1[1]} == ' =' && $1 == ??* && ${1[2]} != $' \x28 ' && $zsyh_user_options [equals] == ' on' && $expanded_path [1] != ' /' ]]; then
1126
1133
REPLY=unknown-token # will error out if executed
@@ -1142,15 +1149,23 @@ _zsh_highlight_main_highlighter_check_path()
1142
1149
tmp_path=$tmp_path :h
1143
1150
done
1144
1151
1145
- [[ -L $expanded_path ]] && return 0
1146
- [[ -e $expanded_path ]] && return 0
1152
+ if (( in_command_position )) ; then
1153
+ if [[ -x $expanded_path ]] && [[ $zsyh_user_options [autocd] == on || ! -d $expanded_path ]]; then
1154
+ return 0
1155
+ fi
1156
+ else
1157
+ if [[ -L $expanded_path || -e $expanded_path ]]; then
1158
+ return 0
1159
+ fi
1160
+ fi
1147
1161
1148
1162
# Search the path in CDPATH
1149
- if [[ $expanded_path != /* ]]; then
1150
- local cdpath_dir
1163
+ if [[ $expanded_path != /* ]] &&
1164
+ { (( ! in_command_position )) || [[ $zsyh_user_options [autocd] == on ]] } ; then
1151
1165
# TODO: When we've dropped support for pre-5.0.6 zsh, use the *(Y1) glob qualifier here.
1166
+ local cdpath_dir
1152
1167
for cdpath_dir in $cdpath ; do
1153
- [[ -e " $cdpath_dir /$expanded_path " ]] && return 0
1168
+ [[ -d " $cdpath_dir / $expanded_path " && -x " $cdpath_dir /$expanded_path " ]] && return 0
1154
1169
done
1155
1170
fi
1156
1171
@@ -1162,7 +1177,14 @@ _zsh_highlight_main_highlighter_check_path()
1162
1177
[[ $WIDGET != zle-line-finish ]]; then
1163
1178
# TODO: When we've dropped support for pre-5.0.6 zsh, use the *(Y1) glob qualifier here.
1164
1179
local -a tmp
1165
- tmp=( ${expanded_path} * (N) )
1180
+ if (( in_command_position )) ; then
1181
+ # We include directories even when autocd is enabled, because those
1182
+ # directories might contain executable files: e.g., BUFFER="/bi" en route
1183
+ # to typing "/bin/sh".
1184
+ tmp=( ${expanded_path} * (N-* ,N-/) )
1185
+ else
1186
+ tmp=( ${expanded_path} * (N) )
1187
+ fi
1166
1188
(( ${+tmp[1]} )) && REPLY=path_prefix && return 0
1167
1189
fi
1168
1190
@@ -1173,6 +1195,8 @@ _zsh_highlight_main_highlighter_check_path()
1173
1195
# Highlight an argument and possibly special chars in quotes starting at $1 in $arg
1174
1196
# This command will at least highlight $1 to end_pos with the default style
1175
1197
# If $2 is set to 0, the argument cannot be highlighted as an option.
1198
+ #
1199
+ # This function currently assumes it's never called for the command word.
1176
1200
_zsh_highlight_main_highlighter_highlight_argument ()
1177
1201
{
1178
1202
local base_style=default i=$1 option_eligible=${2:- 1} path_eligible=1 ret start style
@@ -1307,7 +1331,8 @@ _zsh_highlight_main_highlighter_highlight_argument()
1307
1331
else
1308
1332
base_style=numeric-fd
1309
1333
fi
1310
- elif _zsh_highlight_main_highlighter_check_path $arg [$1 ,-1]; then
1334
+ # This function is currently never called for the command word, so $2 is hard-coded as 0.
1335
+ elif _zsh_highlight_main_highlighter_check_path $arg [$1 ,-1] 0; then
1311
1336
base_style=$REPLY
1312
1337
_zsh_highlight_main_highlighter_highlight_path_separators $base_style
1313
1338
highlights+=($reply )
0 commit comments