'main': Highlight global aliases

This commit is contained in:
Daniel Shahaf 2020-03-17 01:06:00 +00:00 committed by Daniel Shahaf
parent 5a44d9f32a
commit 3c5f63d959
3 changed files with 13 additions and 3 deletions

View file

@ -20,6 +20,7 @@ This highlighter defines the following styles:
* `reserved-word` - shell reserved words (`if`, `for`)
* `alias` - aliases
* `suffix-alias` - suffix aliases (requires zsh 5.1.1 or newer)
* `global-alias` - global aliases
* `builtin` - shell builtin commands (`shift`, `pwd`, `zstyle`)
* `function` - function names
* `command` - command names

View file

@ -33,6 +33,7 @@
: ${ZSH_HIGHLIGHT_STYLES[unknown-token]:=fg=red,bold}
: ${ZSH_HIGHLIGHT_STYLES[reserved-word]:=fg=yellow}
: ${ZSH_HIGHLIGHT_STYLES[suffix-alias]:=fg=green,underline}
: ${ZSH_HIGHLIGHT_STYLES[global-alias]:=fg=cyan}
: ${ZSH_HIGHLIGHT_STYLES[precommand]:=fg=green,underline}
: ${ZSH_HIGHLIGHT_STYLES[commandseparator]:=none}
: ${ZSH_HIGHLIGHT_STYLES[path]:=underline}
@ -106,6 +107,7 @@ _zsh_highlight_main_calculate_fallback() {
local -A fallback_of; fallback_of=(
alias arg0
suffix-alias arg0
global-alias dollar-double-quoted-argument
builtin arg0
function arg0
command arg0
@ -178,7 +180,9 @@ _zsh_highlight_main__type() {
if (( $+aliases[(e)$1] )); then
may_cache=0
fi
if (( $+aliases[(e)$1] )) && (( aliases_allowed )); then
if false && (( ${+galiases[(e)$1]} )); then
REPLY='global alias'
elif (( $+aliases[(e)$1] )) && (( aliases_allowed )); then
REPLY=alias
elif [[ $1 == *.* && -n ${1%.*} ]] && (( $+saliases[(e)${1##*.}] )); then
REPLY='suffix alias'
@ -930,6 +934,9 @@ _zsh_highlight_main_highlighter_highlight_list()
('suffix alias')
style=suffix-alias
;;
('global alias')
style=global-alias
;;
(alias) :;;
(builtin) style=builtin
[[ $arg == $'\x5b' ]] && braces_stack='Q'"$braces_stack"
@ -1014,6 +1021,8 @@ _zsh_highlight_main_highlighter_highlight_list()
if [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_CONTROL_FLOW:#"$arg"} ]]; then
next_word=':start::start_of_pipeline:'
fi
elif _zsh_highlight_main__type "$arg"; [[ $REPLY == 'global alias' ]]; then # $arg is a global alias that isn't in command position
style=global-alias
else # $arg is a non-command word
case $arg in
($'\x29')

View file

@ -33,6 +33,6 @@ alias -g foo=bar
BUFFER=$'foo foo'
expected_region_highlight=(
'1 3 arg0_global' # foo
'5 7 default' # foo
'1 3 global-alias' # foo
'5 7 global-alias' # foo
)