Support suffix aliases

Fixes zsh-users/zsh-syntax-highlighting#126.
This commit is contained in:
Daniel Shahaf 2015-09-04 18:19:26 +00:00
parent a0b5bc6c71
commit 9310d8ae71
2 changed files with 5 additions and 0 deletions

View File

@ -25,6 +25,7 @@ This highlighter defines the following styles:
* `unknown-token` - unknown tokens / errors
* `reserved-word` - shell reserved words
* `alias` - aliases
* `suffix-alias` - suffix aliases (requires zsh 5.1.1 or newer)
* `builtin` - shell builtin commands
* `function` - functions
* `command` - commands

View File

@ -34,6 +34,7 @@
: ${ZSH_HIGHLIGHT_STYLES[unknown-token]:=fg=red,bold}
: ${ZSH_HIGHLIGHT_STYLES[reserved-word]:=fg=yellow}
: ${ZSH_HIGHLIGHT_STYLES[alias]:=fg=green}
: ${ZSH_HIGHLIGHT_STYLES[suffix-alias]:=fg=green}
: ${ZSH_HIGHLIGHT_STYLES[builtin]:=fg=green}
: ${ZSH_HIGHLIGHT_STYLES[function]:=fg=green}
: ${ZSH_HIGHLIGHT_STYLES[command]:=fg=green}
@ -150,6 +151,9 @@ _zsh_highlight_main_highlighter()
local res="$(LC_ALL=C builtin type -w $arg 2>/dev/null)"
case $res in
*': reserved') style=$ZSH_HIGHLIGHT_STYLES[reserved-word];;
*': suffix alias')
style=$ZSH_HIGHLIGHT_STYLES[suffix-alias]
;;
*': alias') style=$ZSH_HIGHLIGHT_STYLES[alias]
local aliased_command="${"$(alias -- $arg)"#*=}"
[[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_FOLLOWED_BY_COMMANDS:#"$aliased_command"} && -z ${(M)ZSH_HIGHLIGHT_TOKENS_FOLLOWED_BY_COMMANDS:#"$arg"} ]] && ZSH_HIGHLIGHT_TOKENS_FOLLOWED_BY_COMMANDS+=($arg)