From 3c5f63d9592df3c544f96950d5b45ee3d96c7fc9 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 17 Mar 2020 01:06:00 +0000 Subject: [PATCH] 'main': Highlight global aliases --- docs/highlighters/main.md | 1 + highlighters/main/main-highlighter.zsh | 11 ++++++++++- highlighters/main/test-data/global-alias1.zsh | 4 ++-- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/docs/highlighters/main.md b/docs/highlighters/main.md index 8f4ef4b..37e7d13 100644 --- a/docs/highlighters/main.md +++ b/docs/highlighters/main.md @@ -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 diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 45d13e2..d3a0fb3 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -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') diff --git a/highlighters/main/test-data/global-alias1.zsh b/highlighters/main/test-data/global-alias1.zsh index 8a66776..0022de3 100644 --- a/highlighters/main/test-data/global-alias1.zsh +++ b/highlighters/main/test-data/global-alias1.zsh @@ -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 )