@@ -973,7 +973,7 @@ _zsh_highlight_main_highlighter_highlight_list()
973
973
fi
974
974
_zsh_highlight_main__stack_pop ' R' reserved-word
975
975
else
976
- if _zsh_highlight_main_highlighter_check_path $arg ; then
976
+ if _zsh_highlight_main_highlighter_check_path $arg 1 ; then
977
977
style=$REPLY
978
978
else
979
979
style=unknown-token
@@ -1077,12 +1077,19 @@ _zsh_highlight_main_highlighter_highlight_path_separators()
1077
1077
# Check if $1 is a path.
1078
1078
# If yes, return 0 and in $REPLY the style to use.
1079
1079
# Else, return non-zero (and the contents of $REPLY is undefined).
1080
+ #
1081
+ # $2 should be non-zero iff we're in command position.
1080
1082
_zsh_highlight_main_highlighter_check_path ()
1081
1083
{
1082
1084
_zsh_highlight_main_highlighter_expand_path " $1 "
1083
1085
local expanded_path=" $REPLY " tmp_path
1086
+ integer in_command_position=$2
1084
1087
1085
- REPLY=path
1088
+ if (( in_command_position )) ; then
1089
+ REPLY=arg0
1090
+ else
1091
+ REPLY=path
1092
+ fi
1086
1093
1087
1094
[[ -z $expanded_path ]] && return 1
1088
1095
@@ -1099,15 +1106,23 @@ _zsh_highlight_main_highlighter_check_path()
1099
1106
tmp_path=$tmp_path :h
1100
1107
done
1101
1108
1102
- [[ -L $expanded_path ]] && return 0
1103
- [[ -e $expanded_path ]] && return 0
1109
+ if (( in_command_position )) ; then
1110
+ if [[ -x $expanded_path ]] && [[ $zsyh_user_options [autocd] == on || ! -d $expanded_path ]]; then
1111
+ return 0
1112
+ fi
1113
+ else
1114
+ if [[ -L $expanded_path || -e $expanded_path ]]; then
1115
+ return 0
1116
+ fi
1117
+ fi
1104
1118
1105
1119
# Search the path in CDPATH
1106
- if [[ $expanded_path != /* ]]; then
1107
- local cdpath_dir
1120
+ if [[ $expanded_path != /* ]] &&
1121
+ { (( ! in_command_position )) || [[ $zsyh_user_options [autocd] == on ]] } ; then
1108
1122
# TODO: When we've dropped support for pre-5.0.6 zsh, use the *(Y1) glob qualifier here.
1123
+ local cdpath_dir
1109
1124
for cdpath_dir in $cdpath ; do
1110
- [[ -e " $cdpath_dir /$expanded_path " ]] && return 0
1125
+ [[ -d " $cdpath_dir / $expanded_path " && -x " $cdpath_dir /$expanded_path " ]] && return 0
1111
1126
done
1112
1127
fi
1113
1128
@@ -1119,7 +1134,14 @@ _zsh_highlight_main_highlighter_check_path()
1119
1134
[[ $WIDGET != zle-line-finish ]]; then
1120
1135
# TODO: When we've dropped support for pre-5.0.6 zsh, use the *(Y1) glob qualifier here.
1121
1136
local -a tmp
1122
- tmp=( ${expanded_path} * (N) )
1137
+ if (( in_command_position )) ; then
1138
+ # We include directories even when autocd is enabled, because those
1139
+ # directories might contain executable files: e.g., BUFFER="/bi" en route
1140
+ # to typing "/bin/sh".
1141
+ tmp=( ${expanded_path} * (N-* ,N-/) )
1142
+ else
1143
+ tmp=( ${expanded_path} * (N) )
1144
+ fi
1123
1145
(( ${+tmp[1]} )) && REPLY=path_prefix && return 0
1124
1146
fi
1125
1147
@@ -1130,6 +1152,8 @@ _zsh_highlight_main_highlighter_check_path()
1130
1152
# Highlight an argument and possibly special chars in quotes starting at $1 in $arg
1131
1153
# This command will at least highlight $1 to end_pos with the default style
1132
1154
# If $2 is set to 0, the argument cannot be highlighted as an option.
1155
+ #
1156
+ # This function currently assumes it's never called for the command word.
1133
1157
_zsh_highlight_main_highlighter_highlight_argument ()
1134
1158
{
1135
1159
local base_style=default i=$1 option_eligible=${2:- 1} path_eligible=1 ret start style
@@ -1250,7 +1274,8 @@ _zsh_highlight_main_highlighter_highlight_argument()
1250
1274
esac
1251
1275
done
1252
1276
1253
- if (( path_eligible )) && _zsh_highlight_main_highlighter_check_path $arg [$1 ,-1]; then
1277
+ # This function is currently never called for the command word, so $2 is hard-coded as 0.
1278
+ if (( path_eligible )) && _zsh_highlight_main_highlighter_check_path $arg [$1 ,-1] 0; then
1254
1279
base_style=$REPLY
1255
1280
_zsh_highlight_main_highlighter_highlight_path_separators $base_style
1256
1281
highlights+=($reply )
0 commit comments