'main': Break out a new helper function for readability.

This commit is contained in:
Daniel Shahaf 2018-01-12 13:46:11 +00:00 committed by Matthew Martin
parent f3425e18fe
commit 3a33ac1d20

View File

@ -174,6 +174,17 @@ _zsh_highlight_main__type() {
return $?
}
# Checks whether $1 is something that can be run.
#
# Return 0 if runnable, 1 if not runnable, 2 if trouble.
_zsh_highlight_main__is_runnable() {
if _zsh_highlight_main__type "$1"; then
[[ $REPLY != none ]]
else
return 2
fi
}
# Check whether the first argument is a redirection operator token.
# Report result via the exit code.
_zsh_highlight_main__is_redirection() {
@ -586,7 +597,7 @@ _zsh_highlight_main_highlighter_highlight_list()
style=reserved-word # de facto a reserved word, although not de jure
next_word=':start:'
elif [[ $this_word == *':start:'* ]] && (( in_redirection == 0 )); then # $arg is the command word
if (( ${+precommand_options[$arg]} )) && { _zsh_highlight_main__type $arg && [[ $REPLY != "none" ]] }; then
if (( ${+precommand_options[$arg]} )) && _zsh_highlight_main__is_runnable $arg; then
style=precommand
flags_with_argument=${precommand_options[$arg]%:*}
flags_sans_argument=${precommand_options[$arg]#*:}