40
40
: ${ZSH_HIGHLIGHT_STYLES[path_prefix_pathseparator]:= }
41
41
: ${ZSH_HIGHLIGHT_STYLES[globbing]:= fg=blue}
42
42
: ${ZSH_HIGHLIGHT_STYLES[history-expansion]:= fg=blue}
43
- : ${ZSH_HIGHLIGHT_STYLES[command-substitution]:= fg=magenta}
44
- : ${ZSH_HIGHLIGHT_STYLES[process-substitution]:= fg=magenta}
43
+ : ${ZSH_HIGHLIGHT_STYLES[command-substitution]:= none}
44
+ : ${ZSH_HIGHLIGHT_STYLES[command-substitution-delimiter]:= fg=magenta}
45
+ : ${ZSH_HIGHLIGHT_STYLES[process-substitution]:= none}
46
+ : ${ZSH_HIGHLIGHT_STYLES[process-substitution-delimiter]:= fg=magenta}
45
47
: ${ZSH_HIGHLIGHT_STYLES[single-hyphen-option]:= none}
46
48
: ${ZSH_HIGHLIGHT_STYLES[double-hyphen-option]:= none}
47
49
: ${ZSH_HIGHLIGHT_STYLES[back-quoted-argument]:= none}
50
+ : ${ZSH_HIGHLIGHT_STYLES[back-quoted-argument-delimiter]:= fg=magenta}
48
51
: ${ZSH_HIGHLIGHT_STYLES[single-quoted-argument]:= fg=yellow}
49
52
: ${ZSH_HIGHLIGHT_STYLES[double-quoted-argument]:= fg=yellow}
50
53
: ${ZSH_HIGHLIGHT_STYLES[dollar-quoted-argument]:= fg=yellow}
@@ -103,6 +106,10 @@ _zsh_highlight_main_calculate_fallback() {
103
106
double-quoted-argument{-unclosed,}
104
107
dollar-quoted-argument{-unclosed,}
105
108
back-quoted-argument{-unclosed,}
109
+
110
+ command-substitution{-delimiter,}
111
+ process-substitution{-delimiter,}
112
+ back-quoted-argument{-delimiter,}
106
113
)
107
114
local needle=$1 value
108
115
reply=($1 )
@@ -852,7 +859,7 @@ _zsh_highlight_main_highlighter_check_path()
852
859
# This command will at least highlight $1 to end_pos with the default style
853
860
_zsh_highlight_main_highlighter_highlight_argument ()
854
861
{
855
- local base_style=default i=$1 path_eligible=1 start style
862
+ local base_style=default i=$1 path_eligible=1 ret start style
856
863
local -a highlights
857
864
858
865
local -a match mbegin mend
@@ -871,8 +878,16 @@ _zsh_highlight_main_highlighter_highlight_argument()
871
878
if [[ $arg [i+1] == $' \x28 ' ]]; then
872
879
(( i += 2 ))
873
880
_zsh_highlight_main_highlighter_XXX $(( start_pos + i - 1 )) S $has_end $arg [i,end_pos]
881
+ ret=$?
874
882
(( i += REPLY ))
875
- highlights+=($(( start_pos + $1 - 1 )) $(( start_pos + i )) process-substitution $reply )
883
+ highlights+=(
884
+ $(( start_pos + $1 - 1 )) $(( start_pos + i )) process-substitution
885
+ $(( start_pos + $1 - 1 )) $(( start_pos + $1 + 1 )) process-substitution-delimiter
886
+ $reply
887
+ )
888
+ if (( ret == 0 )) ; then
889
+ highlights+=($(( start_pos + i - 1 )) $(( start_pos + i )) process-substitution-delimiter)
890
+ fi
876
891
fi
877
892
esac
878
893
@@ -906,8 +921,16 @@ _zsh_highlight_main_highlighter_highlight_argument()
906
921
start=$i
907
922
(( i += 2 ))
908
923
_zsh_highlight_main_highlighter_XXX $(( start_pos + i - 1 )) S $has_end $arg [i,end_pos]
924
+ ret=$?
909
925
(( i += REPLY ))
910
- highlights+=($(( start_pos + start - 1 )) $(( start_pos + i )) command-substitution $reply )
926
+ highlights+=(
927
+ $(( start_pos + start - 1 )) $(( start_pos + i )) command-substitution
928
+ $(( start_pos + start - 1 )) $(( start_pos + start + 1 )) command-substitution-delimiter
929
+ $reply
930
+ )
931
+ if (( ret == 0 )) ; then
932
+ highlights+=($(( start_pos + i - 1 )) $(( start_pos + i )) command-substitution-delimiter)
933
+ fi
911
934
continue
912
935
fi
913
936
while [[ $arg [i+1] == [\^ =~ # +] ]]; do
@@ -921,8 +944,16 @@ _zsh_highlight_main_highlighter_highlight_argument()
921
944
start=$i
922
945
(( i += 2 ))
923
946
_zsh_highlight_main_highlighter_XXX $(( start_pos + i - 1 )) S $has_end $arg [i,end_pos]
947
+ ret=$?
924
948
(( i += REPLY ))
925
- highlights+=($(( start_pos + start - 1 )) $(( start_pos + i )) process-substitution $reply )
949
+ highlights+=(
950
+ $(( start_pos + start - 1 )) $(( start_pos + i )) process-substitution
951
+ $(( start_pos + start - 1 )) $(( start_pos + start + 1 )) process-substitution-delimiter
952
+ $reply
953
+ )
954
+ if (( ret == 0 )) ; then
955
+ highlights+=($(( start_pos + i - 1 )) $(( start_pos + i )) process-substitution-delimiter)
956
+ fi
926
957
continue
927
958
fi
928
959
; |
@@ -987,7 +1018,7 @@ _zsh_highlight_main_highlighter_highlight_double_quote()
987
1018
{
988
1019
local -a match mbegin mend saved_reply
989
1020
local MATCH; integer MBEGIN MEND
990
- local i j k style
1021
+ local i j k ret style
991
1022
reply=()
992
1023
993
1024
for (( i = $1 + 1 ; i <= end_pos - start_pos ; i += 1 )) ; do
@@ -1021,8 +1052,17 @@ _zsh_highlight_main_highlighter_highlight_double_quote()
1021
1052
(( i += 2 ))
1022
1053
saved_reply=($reply )
1023
1054
_zsh_highlight_main_highlighter_XXX $(( start_pos + i - 1 )) S $has_end $arg [i,end_pos]
1055
+ ret=$?
1024
1056
(( i += REPLY ))
1025
- reply=($saved_reply $j $(( start_pos + i )) command-substitution $reply )
1057
+ reply=(
1058
+ $saved_reply
1059
+ $j $(( start_pos + i )) command-substitution
1060
+ $j $(( j + 2 )) command-substitution-delimiter
1061
+ $reply
1062
+ )
1063
+ if (( ret == 0 )) ; then
1064
+ reply+=($(( start_pos + i - 1 )) $(( start_pos + i )) command-substitution-delimiter)
1065
+ fi
1026
1066
continue
1027
1067
else
1028
1068
continue
@@ -1123,11 +1163,9 @@ _zsh_highlight_main_highlighter_highlight_backtick()
1123
1163
# offset is a count of consumed \ (the delta between buf and arg).
1124
1164
# offsets is an array indexed by buf offset of when the delta between buf and arg changes.
1125
1165
# It is sparse, so search backwards to the last value
1126
- # unclosed is an array of one highlight to append to reply if this back-quoted-argument
1127
- # is closed and there is an unclosed back-quoted-argument in buf.
1128
- local buf highlight style=back-quoted-argument-unclosed
1166
+ local buf highlight style=back-quoted-argument-unclosed style_end
1129
1167
local -i arg1=$1 end_ i=$1 last offset=0 start subshell_has_end=0
1130
- local -a highlight_zone highlights offsets unclosed
1168
+ local -a highlight_zone highlights offsets
1131
1169
reply=()
1132
1170
1133
1171
last=$(( arg1 + 1 ))
@@ -1154,6 +1192,7 @@ _zsh_highlight_main_highlighter_highlight_backtick()
1154
1192
fi
1155
1193
else # it's an unquoted ` and this is the end
1156
1194
style=back-quoted-argument
1195
+ style_end=back-quoted-argument-delimiter
1157
1196
buf=$buf$arg [last,i-1]
1158
1197
offsets[i-arg1-offset]=' ' # So we never index past the end
1159
1198
break
@@ -1170,11 +1209,18 @@ _zsh_highlight_main_highlighter_highlight_backtick()
1170
1209
highlights+=($start $end_ $highlight )
1171
1210
if [[ $highlight == back-quoted-argument-unclosed && $style == back-quoted-argument ]]; then
1172
1211
# An inner backtick command substitution is unclosed, but this level is closed
1173
- unclosed=( $(( start_pos + i - 1 )) $(( start_pos + i )) unknown-token)
1212
+ style_end= unknown-token
1174
1213
fi
1175
1214
done
1176
1215
1177
- reply= ($(( start_pos + arg1 - 1 )) $(( start_pos + i )) $style $highlights $unclosed )
1216
+ reply= (
1217
+ $(( start_pos + arg1 - 1 )) $(( start_pos + i )) $style
1218
+ $(( start_pos + arg1 - 1 )) $(( start_pos + arg1 )) back-quoted-argument-delimiter
1219
+ $highlights
1220
+ )
1221
+ if (( $# style_end )) ; then
1222
+ reply+=($(( start_pos + i - 1 )) $(( start_pos + i )) $style_end )
1223
+ fi
1178
1224
REPLY= $i
1179
1225
}
1180
1226
0 commit comments