Skip to content

Commit

Permalink
'main': Highlight the 'command' precommand.
Browse files Browse the repository at this point in the history
Fixes #343.
  • Loading branch information
danielshahaf authored and phy1729 committed Oct 11, 2018
1 parent 4c7db4e commit 5694221
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
9 changes: 5 additions & 4 deletions highlighters/main/main-highlighter.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ _zsh_highlight_highlighter_main_paint()
# for that precommand.
local -A precommand_options
precommand_options=(
'command' ''
'sudo' Cgprtu
)

Expand All @@ -263,7 +264,7 @@ _zsh_highlight_highlighter_main_paint()
# ';;' ';&' ';|'
)
ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS=(
'builtin' 'command' 'exec' 'nocorrect' 'noglob'
'builtin' 'exec' 'nocorrect' 'noglob'
'pkexec' # immune to #121 because it's usually not passed --option flags
)

Expand Down Expand Up @@ -572,14 +573,14 @@ _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 [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS:#"$arg"} ]]; then
style=precommand
elif (( ${+precommand_options[$arg]} )) && { _zsh_highlight_main__type $arg; [[ -n $REPLY && $REPLY != "none" ]] }; then
if (( ${+precommand_options[$arg]} )) && { _zsh_highlight_main__type $arg; [[ -n $REPLY && $REPLY != "none" ]] }; then
style=precommand
flags_with_argument=${precommand_options[$arg]}
next_word=${next_word//:regular:/}
next_word+=':sudo_opt:'
next_word+=':start:'
elif [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS:#"$arg"} ]]; then
style=precommand
else
case $res in
reserved) # reserved word
Expand Down
4 changes: 2 additions & 2 deletions highlighters/main/test-data/precommand2.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ BUFFER='command -v ls'

expected_region_highlight=(
"1 7 precommand" # command
"9 10 single-hyphen-option 'issue #343'" # -v
"12 13 command 'issue #343'" # ls
"9 10 single-hyphen-option" # -v
"12 13 command" # ls
)

0 comments on commit 5694221

Please sign in to comment.