From 3a33ac1d202176c371bc7c3c33f433d5686c30d7 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 12 Jan 2018 13:46:11 +0000 Subject: [PATCH] 'main': Break out a new helper function for readability. --- highlighters/main/main-highlighter.zsh | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 47c9cae..c5e45a8 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -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]#*:}