main: Highlight <( ) and >( ) process substitutions

Fixes #494
This commit is contained in:
Matthew Martin 2018-03-10 15:03:25 -06:00
parent 3ac7d1c785
commit 08d4401fae
3 changed files with 15 additions and 1 deletions

View file

@ -33,6 +33,7 @@ This highlighter defines the following styles:
* `globbing` - globbing expressions (`*.txt`) * `globbing` - globbing expressions (`*.txt`)
* `history-expansion` - history expansion expressions (`!foo` and `^foo^bar`) * `history-expansion` - history expansion expressions (`!foo` and `^foo^bar`)
* `command-substitution` - command substitutions (`$(echo foo)`) * `command-substitution` - command substitutions (`$(echo foo)`)
* `process-substitution` - process substitutions (`<(echo foo)`)
* `single-hyphen-option` - single-hyphen options (`-o`) * `single-hyphen-option` - single-hyphen options (`-o`)
* `double-hyphen-option` - double-hyphen options (`--option`) * `double-hyphen-option` - double-hyphen options (`--option`)
* `back-quoted-argument` - backtick command substitution (`` `foo` ``) * `back-quoted-argument` - backtick command substitution (`` `foo` ``)

View file

@ -41,6 +41,7 @@
: ${ZSH_HIGHLIGHT_STYLES[globbing]:=fg=blue} : ${ZSH_HIGHLIGHT_STYLES[globbing]:=fg=blue}
: ${ZSH_HIGHLIGHT_STYLES[history-expansion]:=fg=blue} : ${ZSH_HIGHLIGHT_STYLES[history-expansion]:=fg=blue}
: ${ZSH_HIGHLIGHT_STYLES[command-substitution]:=fg=magenta} : ${ZSH_HIGHLIGHT_STYLES[command-substitution]:=fg=magenta}
: ${ZSH_HIGHLIGHT_STYLES[process-substitution]:=fg=magenta}
: ${ZSH_HIGHLIGHT_STYLES[single-hyphen-option]:=none} : ${ZSH_HIGHLIGHT_STYLES[single-hyphen-option]:=none}
: ${ZSH_HIGHLIGHT_STYLES[double-hyphen-option]:=none} : ${ZSH_HIGHLIGHT_STYLES[double-hyphen-option]:=none}
: ${ZSH_HIGHLIGHT_STYLES[back-quoted-argument]:=none} : ${ZSH_HIGHLIGHT_STYLES[back-quoted-argument]:=none}
@ -896,6 +897,16 @@ _zsh_highlight_main_highlighter_highlight_argument()
if [[ $arg[i+1] == [*@#?$!-] ]]; then if [[ $arg[i+1] == [*@#?$!-] ]]; then
(( i += 1 )) (( i += 1 ))
fi;; fi;;
[\<\>])
if [[ $arg[i+1] == $'\x28' ]]; then # \x28 = open paren
start=$i
(( i += 2 ))
_zsh_highlight_main_highlighter_highlight_list $(( start_pos + i - 1 )) S $has_end $arg[i,end_pos]
(( i += REPLY ))
highlights+=($(( start_pos + start - 1)) $(( start_pos + i )) process-substitution $reply)
continue
fi
;|
*) *)
if $highlight_glob && [[ ${arg[$i]} =~ ^[*?] || ${arg:$i-1} =~ ^\<[0-9]*-[0-9]*\> ]]; then if $highlight_glob && [[ ${arg[$i]} =~ ^[*?] || ${arg:$i-1} =~ ^\<[0-9]*-[0-9]*\> ]]; then
highlights+=($(( start_pos + i - 1 )) $(( start_pos + i + $#MATCH - 1)) globbing) highlights+=($(( start_pos + i - 1 )) $(( start_pos + i + $#MATCH - 1)) globbing)

View file

@ -31,7 +31,9 @@ BUFFER='ls >(wc) | nl'
expected_region_highlight=( expected_region_highlight=(
"1 2 command" # ls "1 2 command" # ls
"4 8 process-substitution 'issue #494'" # >(wc) "4 8 default" # >(wc)
"4 8 process-substitution" # >(wc)
"6 7 command" # wc
"10 10 commandseparator" # | "10 10 commandseparator" # |
"12 13 command" # nl "12 13 command" # nl
) )