@@ -857,7 +857,7 @@ _zsh_highlight_main_highlighter_highlight_list()
857
857
fi
858
858
_zsh_highlight_main__stack_pop ' R' reserved-word
859
859
else
860
- if _zsh_highlight_main_highlighter_check_path $arg ; then
860
+ if _zsh_highlight_main_highlighter_check_path $arg 1 ; then
861
861
style=$REPLY
862
862
else
863
863
style=unknown-token
@@ -960,10 +960,13 @@ _zsh_highlight_main_highlighter_highlight_path_separators()
960
960
# Check if $1 is a path.
961
961
# If yes, return 0 and in $REPLY the style to use.
962
962
# Else, return non-zero (and the contents of $REPLY is undefined).
963
+ #
964
+ # $2 should be non-zero iff we're in command position.
963
965
_zsh_highlight_main_highlighter_check_path ()
964
966
{
965
967
_zsh_highlight_main_highlighter_expand_path " $1 "
966
968
local expanded_path=" $REPLY " tmp_path
969
+ integer in_command_position=$2
967
970
968
971
REPLY=path
969
972
@@ -982,16 +985,25 @@ _zsh_highlight_main_highlighter_check_path()
982
985
tmp_path=$tmp_path :h
983
986
done
984
987
985
- [[ -L $expanded_path ]] && return 0
986
- [[ -e $expanded_path ]] && return 0
988
+ if (( in_command_position )) ; then
989
+ if [[ -x $expanded_path ]] && [[ $zsyh_user_options [autocd] == on || ! -d $expanded_path ]]; then
990
+ return 0
991
+ fi
992
+ else
993
+ if [[ -L $expanded_path || -e $expanded_path ]]; then
994
+ return 0
995
+ fi
996
+ fi
987
997
988
998
# Search the path in CDPATH
989
999
if [[ $expanded_path != /* ]]; then
990
- local cdpath_dir
991
1000
# TODO: When we've dropped support for pre-5.0.6 zsh, use the *(Y1) glob qualifier here.
992
- for cdpath_dir in $cdpath ; do
993
- [[ -e " $cdpath_dir /$expanded_path " ]] && return 0
994
- done
1001
+ if (( ! in_command_position )) || [[ $zsyh_user_options [autocd] == on ]]; then
1002
+ local cdpath_dir
1003
+ for cdpath_dir in $cdpath ; do
1004
+ [[ -d " $cdpath_dir /$expanded_path " && -x " $cdpath_dir /$expanded_path " ]] && return 0
1005
+ done
1006
+ fi
995
1007
fi
996
1008
997
1009
# If dirname($1) doesn't exist, neither does $1.
@@ -1012,6 +1024,8 @@ _zsh_highlight_main_highlighter_check_path()
1012
1024
# Highlight an argument and possibly special chars in quotes starting at $1 in $arg
1013
1025
# This command will at least highlight $1 to end_pos with the default style
1014
1026
# If $2 is set to 0, the argument cannot be highlighted as an option.
1027
+ #
1028
+ # This function currently assumes it's never called for the command word.
1015
1029
_zsh_highlight_main_highlighter_highlight_argument ()
1016
1030
{
1017
1031
local base_style=default i=$1 option_eligible=${2:- 1} path_eligible=1 ret start style
@@ -1132,7 +1146,8 @@ _zsh_highlight_main_highlighter_highlight_argument()
1132
1146
esac
1133
1147
done
1134
1148
1135
- if (( path_eligible )) && _zsh_highlight_main_highlighter_check_path $arg [$1 ,-1]; then
1149
+ # This function is currently never called for the command word, so $2 is hard-coded as 0.
1150
+ if (( path_eligible )) && _zsh_highlight_main_highlighter_check_path $arg [$1 ,-1] 0; then
1136
1151
base_style=$REPLY
1137
1152
_zsh_highlight_main_highlighter_highlight_path_separators $base_style
1138
1153
highlights+=($reply )
0 commit comments