From bfabffbf975cd846a6e3098cac2a70b3ac3f8d33 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 9 May 2016 03:26:29 +0000 Subject: [PATCH] 'main': Factor out common code. No functional change. --- highlighters/main/main-highlighter.zsh | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index a0f8dba..bfcd882 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -93,6 +93,12 @@ _zsh_highlight_main__type() { LC_ALL=C builtin type -w -- $1 2>/dev/null } +# Check whether the first argument is a redirection operator token. +# Report result via the exit code. +_zsh_highlight_main__is_redirection() { + [[ $1 == (<0-9>|)(\<|\>)* ]] +} + # Main syntax highlighting function. _zsh_highlight_main_highlighter() { @@ -351,7 +357,7 @@ _zsh_highlight_main_highlighter() else style=unknown-token fi - elif [[ $arg == (<0-9>|)(\<|\>)* ]]; then + elif _zsh_highlight_main__is_redirection $arg; then # A '<' or '>', possibly followed by a digit style=redirection (( in_redirection=2 )) @@ -421,7 +427,7 @@ _zsh_highlight_main_highlighter() else style=unknown-token fi - elif [[ $arg == (<0-9>|)(\<|\>)* ]]; then + elif _zsh_highlight_main__is_redirection $arg; then style=redirection (( in_redirection=2 )) else