Skip to content

Commit 3c5f63d

Browse files
committed
'main': Highlight global aliases
1 parent 5a44d9f commit 3c5f63d

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

docs/highlighters/main.md

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ This highlighter defines the following styles:
2020
* `reserved-word` - shell reserved words (`if`, `for`)
2121
* `alias` - aliases
2222
* `suffix-alias` - suffix aliases (requires zsh 5.1.1 or newer)
23+
* `global-alias` - global aliases
2324
* `builtin` - shell builtin commands (`shift`, `pwd`, `zstyle`)
2425
* `function` - function names
2526
* `command` - command names

highlighters/main/main-highlighter.zsh

+10-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
: ${ZSH_HIGHLIGHT_STYLES[unknown-token]:=fg=red,bold}
3434
: ${ZSH_HIGHLIGHT_STYLES[reserved-word]:=fg=yellow}
3535
: ${ZSH_HIGHLIGHT_STYLES[suffix-alias]:=fg=green,underline}
36+
: ${ZSH_HIGHLIGHT_STYLES[global-alias]:=fg=cyan}
3637
: ${ZSH_HIGHLIGHT_STYLES[precommand]:=fg=green,underline}
3738
: ${ZSH_HIGHLIGHT_STYLES[commandseparator]:=none}
3839
: ${ZSH_HIGHLIGHT_STYLES[path]:=underline}
@@ -106,6 +107,7 @@ _zsh_highlight_main_calculate_fallback() {
106107
local -A fallback_of; fallback_of=(
107108
alias arg0
108109
suffix-alias arg0
110+
global-alias dollar-double-quoted-argument
109111
builtin arg0
110112
function arg0
111113
command arg0
@@ -178,7 +180,9 @@ _zsh_highlight_main__type() {
178180
if (( $+aliases[(e)$1] )); then
179181
may_cache=0
180182
fi
181-
if (( $+aliases[(e)$1] )) && (( aliases_allowed )); then
183+
if false && (( ${+galiases[(e)$1]} )); then
184+
REPLY='global alias'
185+
elif (( $+aliases[(e)$1] )) && (( aliases_allowed )); then
182186
REPLY=alias
183187
elif [[ $1 == *.* && -n ${1%.*} ]] && (( $+saliases[(e)${1##*.}] )); then
184188
REPLY='suffix alias'
@@ -930,6 +934,9 @@ _zsh_highlight_main_highlighter_highlight_list()
930934
('suffix alias')
931935
style=suffix-alias
932936
;;
937+
('global alias')
938+
style=global-alias
939+
;;
933940
(alias) :;;
934941
(builtin) style=builtin
935942
[[ $arg == $'\x5b' ]] && braces_stack='Q'"$braces_stack"
@@ -1014,6 +1021,8 @@ _zsh_highlight_main_highlighter_highlight_list()
10141021
if [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_CONTROL_FLOW:#"$arg"} ]]; then
10151022
next_word=':start::start_of_pipeline:'
10161023
fi
1024+
elif _zsh_highlight_main__type "$arg"; [[ $REPLY == 'global alias' ]]; then # $arg is a global alias that isn't in command position
1025+
style=global-alias
10171026
else # $arg is a non-command word
10181027
case $arg in
10191028
($'\x29')

highlighters/main/test-data/global-alias1.zsh

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,6 @@ alias -g foo=bar
3333
BUFFER=$'foo foo'
3434

3535
expected_region_highlight=(
36-
'1 3 arg0_global' # foo
37-
'5 7 default' # foo
36+
'1 3 global-alias' # foo
37+
'5 7 global-alias' # foo
3838
)

0 commit comments

Comments
 (0)