command word: Avoid unknown-token highlighting whilst inputting the command word.

Adds the 'command-being-input' highlight.

Builds on top of the 'command-word-separator-v1' branch from PR #243.
This commit is contained in:
Daniel Shahaf 2015-11-27 08:51:49 +00:00
parent 09c4114eb9
commit e13c86dfc2
3 changed files with 7 additions and 1 deletions

View File

@ -26,6 +26,7 @@ This highlighter defines the following styles:
* `precommand` - precommand modifiers (e.g., `noglob`, `builtin`) * `precommand` - precommand modifiers (e.g., `noglob`, `builtin`)
* `commandseparator` - command separation tokens (`;`, `&&`) * `commandseparator` - command separation tokens (`;`, `&&`)
* `hashed-command` - hashed commands * `hashed-command` - hashed commands
* `command-being-typed` - prefix of a command/function/alias that isn't one itself (e.g., `sourc`, `ifconfi`)
* `path` - existing filenames * `path` - existing filenames
* `path_prefix` - prefixes of existing filenames * `path_prefix` - prefixes of existing filenames
* `globbing` - globbing expressions (`*.txt`) * `globbing` - globbing expressions (`*.txt`)

View File

@ -40,6 +40,7 @@
: ${ZSH_HIGHLIGHT_STYLES[precommand]:=fg=green,underline} : ${ZSH_HIGHLIGHT_STYLES[precommand]:=fg=green,underline}
: ${ZSH_HIGHLIGHT_STYLES[commandseparator]:=none} : ${ZSH_HIGHLIGHT_STYLES[commandseparator]:=none}
: ${ZSH_HIGHLIGHT_STYLES[hashed-command]:=fg=green} : ${ZSH_HIGHLIGHT_STYLES[hashed-command]:=fg=green}
: ${ZSH_HIGHLIGHT_STYLES[command-being-typed]:=fg=yellow,underline}
: ${ZSH_HIGHLIGHT_STYLES[path]:=underline} : ${ZSH_HIGHLIGHT_STYLES[path]:=underline}
: ${ZSH_HIGHLIGHT_STYLES[path_prefix]:=underline} : ${ZSH_HIGHLIGHT_STYLES[path_prefix]:=underline}
: ${ZSH_HIGHLIGHT_STYLES[globbing]:=fg=blue} : ${ZSH_HIGHLIGHT_STYLES[globbing]:=fg=blue}
@ -347,6 +348,8 @@ _zsh_highlight_main_highlighter()
else else
if _zsh_highlight_main_highlighter_check_path; then if _zsh_highlight_main_highlighter_check_path; then
style=$ZSH_HIGHLIGHT_STYLES[path] style=$ZSH_HIGHLIGHT_STYLES[path]
elif (( ${#BUFFER} == $end_pos )); then
style=$ZSH_HIGHLIGHT_STYLES[command-being-typed]
else else
style=$ZSH_HIGHLIGHT_STYLES[unknown-token] style=$ZSH_HIGHLIGHT_STYLES[unknown-token]
fi fi

View File

@ -27,8 +27,10 @@
# vim: ft=zsh sw=2 ts=2 et # vim: ft=zsh sw=2 ts=2 et
# ------------------------------------------------------------------------------------------------- # -------------------------------------------------------------------------------------------------
BUFFER='azertyuiop' # Do not append to the BUFFER; the second instance tests an "at end of BUFFER" feature.
BUFFER='azertyuiop; azertyuiop'
expected_region_highlight=( expected_region_highlight=(
"1 10 $ZSH_HIGHLIGHT_STYLES[unknown-token]" # azertyuiop "1 10 $ZSH_HIGHLIGHT_STYLES[unknown-token]" # azertyuiop
"13 22 $ZSH_HIGHLIGHT_STYLES[command-being-typed]" # azertyuiop, at end of buffer
) )