aliases: Highlight aliases with '=' in their LHS as error. (Part of issue #263.)

This commit is contained in:
Daniel Shahaf 2016-01-11 15:07:18 +00:00
parent 5e4b446dee
commit 28932316cc
2 changed files with 23 additions and 4 deletions

View File

@ -294,9 +294,28 @@ _zsh_highlight_main_highlighter()
*': suffix alias') *': suffix alias')
style=$ZSH_HIGHLIGHT_STYLES[suffix-alias] style=$ZSH_HIGHLIGHT_STYLES[suffix-alias]
;; ;;
*': alias') style=$ZSH_HIGHLIGHT_STYLES[alias] *': alias') () {
local aliased_command="${"$(alias -- $arg)"#*=}" integer insane_alias
[[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS:#"$aliased_command"} && -z ${(M)ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS:#"$arg"} ]] && ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS+=($arg) case $arg in
# Issue #263: aliases with '=' on their LHS.
#
# There are three cases:
#
# - Unsupported, breaks 'alias -L' output, but invokable:
('='*) :;;
# - Unsupported, not invokable:
(*'='*) insane_alias=1;;
# - The common case:
(*) :;;
esac
if (( insane_alias )); then
style=$ZSH_HIGHLIGHT_STYLES[unknown-token]
else
style=$ZSH_HIGHLIGHT_STYLES[alias]
local aliased_command="${"$(alias -- $arg)"#*=}"
[[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS:#"$aliased_command"} && -z ${(M)ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS:#"$arg"} ]] && ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS+=($arg)
fi
}
;; ;;
*': builtin') style=$ZSH_HIGHLIGHT_STYLES[builtin];; *': builtin') style=$ZSH_HIGHLIGHT_STYLES[builtin];;
*': function') style=$ZSH_HIGHLIGHT_STYLES[function];; *': function') style=$ZSH_HIGHLIGHT_STYLES[function];;

View File

@ -34,5 +34,5 @@ ZSH_HIGHLIGHT_STYLES[alias]=$unused_highlight
BUFFER='x=y ls' BUFFER='x=y ls'
expected_region_highlight=( expected_region_highlight=(
"1 3 $ZSH_HIGHLIGHT_STYLES[unknown-token] 'issue #263, #issuecomment-170579803'" # x=y "1 3 $ZSH_HIGHLIGHT_STYLES[unknown-token]" # x=y
) )