'main': Optionally ignore aliases in __type
This commit is contained in:
parent
b9d7fe5a43
commit
02f4a6b540
@ -128,22 +128,36 @@ _zsh_highlight_main_calculate_fallback() {
|
|||||||
# Uses the zsh/parameter module if available to avoid forks, and a
|
# Uses the zsh/parameter module if available to avoid forks, and a
|
||||||
# wrapper around 'type -w' as fallback.
|
# wrapper around 'type -w' as fallback.
|
||||||
#
|
#
|
||||||
# Takes a single argument.
|
# If $2 is 0, do not consider aliases.
|
||||||
#
|
#
|
||||||
# The result will be stored in REPLY.
|
# The result will be stored in REPLY.
|
||||||
_zsh_highlight_main__type() {
|
_zsh_highlight_main__type() {
|
||||||
|
integer -r aliases_allowed=${2-1}
|
||||||
|
# We won't cache replies of anything that exists as an alias at all, to
|
||||||
|
# ensure the cached value is correct regardless of $aliases_allowed.
|
||||||
|
#
|
||||||
|
# ### We probably _should_ cache them in a cache that's keyed on the value of
|
||||||
|
# ### $aliases_allowed, on the assumption that aliases are the common case.
|
||||||
|
integer may_cache=1
|
||||||
|
|
||||||
|
# Cache lookup
|
||||||
if (( $+_zsh_highlight_main__command_type_cache )); then
|
if (( $+_zsh_highlight_main__command_type_cache )); then
|
||||||
REPLY=$_zsh_highlight_main__command_type_cache[(e)$1]
|
REPLY=$_zsh_highlight_main__command_type_cache[(e)$1]
|
||||||
if [[ -n "$REPLY" ]]; then
|
if [[ -n "$REPLY" ]]; then
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Main logic
|
||||||
if (( $#options_to_set )); then
|
if (( $#options_to_set )); then
|
||||||
setopt localoptions $options_to_set;
|
setopt localoptions $options_to_set;
|
||||||
fi
|
fi
|
||||||
unset REPLY
|
unset REPLY
|
||||||
if zmodload -e zsh/parameter; then
|
if zmodload -e zsh/parameter; then
|
||||||
if (( $+aliases[(e)$1] )); then
|
if (( $+aliases[(e)$1] )); then
|
||||||
|
may_cache=0
|
||||||
|
fi
|
||||||
|
if (( $+aliases[(e)$1] )) && (( aliases_allowed )); then
|
||||||
REPLY=alias
|
REPLY=alias
|
||||||
elif (( $+saliases[(e)${1##*.}] )); then
|
elif (( $+saliases[(e)${1##*.}] )); then
|
||||||
REPLY='suffix alias'
|
REPLY='suffix alias'
|
||||||
@ -168,9 +182,21 @@ _zsh_highlight_main__type() {
|
|||||||
fi
|
fi
|
||||||
if ! (( $+REPLY )); then
|
if ! (( $+REPLY )); then
|
||||||
# Note that 'type -w' will run 'rehash' implicitly.
|
# Note that 'type -w' will run 'rehash' implicitly.
|
||||||
REPLY="${$(LC_ALL=C builtin type -w -- $1 2>/dev/null)##*: }"
|
#
|
||||||
|
# We 'unalias' in a subshell, so the parent shell is not affected.
|
||||||
|
#
|
||||||
|
# The colon command is there just to avoid a command substitution that
|
||||||
|
# starts with an arithmetic expression [«((…))» as the first thing inside
|
||||||
|
# «$(…)»], which is area that has had some parsing bugs before 5.6
|
||||||
|
# (approximately).
|
||||||
|
REPLY="${$(:; (( aliases_allowed )) || unalias -- $1 2>/dev/null; LC_ALL=C builtin type -w -- $1 2>/dev/null)##*: }"
|
||||||
|
if [[ $REPLY == 'alias' ]]; then
|
||||||
|
may_cache=0
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
if (( $+_zsh_highlight_main__command_type_cache )); then
|
|
||||||
|
# Cache population
|
||||||
|
if (( may_cache )) && (( $+_zsh_highlight_main__command_type_cache )); then
|
||||||
_zsh_highlight_main__command_type_cache[(e)$1]=$REPLY
|
_zsh_highlight_main__command_type_cache[(e)$1]=$REPLY
|
||||||
fi
|
fi
|
||||||
[[ -n $REPLY ]]
|
[[ -n $REPLY ]]
|
||||||
|
Loading…
Reference in New Issue
Block a user