Skip to content

Commit 583291c

Browse files
committed
main: Do not highlight options after --
1 parent 7388adf commit 583291c

File tree

2 files changed

+51
-3
lines changed

2 files changed

+51
-3
lines changed

highlighters/main/main-highlighter.zsh

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ _zsh_highlight_highlighter_main_paint()
365365
# exit code is 0 if the braces_stack is empty, 1 otherwise.
366366
_zsh_highlight_main_highlighter_highlight_list()
367367
{
368-
integer start_pos end_pos=0 buf_offset=$1 has_end=$3
368+
integer start_pos end_pos=0 buf_offset=$1 has_end=$3 seen_dashdash=0
369369
# last_alias is the last alias arg (lhs) expanded (if in an alias).
370370
# This allows for expanding alias ls='ls -l' while avoiding loops.
371371
local arg buf=$4 highlight_glob=true last_alias style
@@ -684,6 +684,7 @@ _zsh_highlight_main_highlighter_highlight_list()
684684

685685
# The Great Fork: is this a command word? Is this a non-command word?
686686
if [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR:#"$arg"} ]]; then
687+
seen_dashdash=0
687688
if [[ $this_word == *':regular:'* ]]; then
688689
# This highlights empty commands (semicolon follows nothing) as an error.
689690
# Zsh accepts them, though.
@@ -990,9 +991,13 @@ _zsh_highlight_main_highlighter_highlight_argument()
990991

991992
case "$arg[i]" in
992993
'-')
993-
if (( option_eligible )); then
994+
if (( option_eligible && ! seen_dashdash )); then
994995
if [[ $arg[i+1] == - ]]; then
995-
base_style=double-hyphen-option
996+
if [[ $#arg == 2 ]]; then
997+
seen_dashdash=1
998+
else
999+
base_style=double-hyphen-option
1000+
fi
9961001
else
9971002
base_style=single-hyphen-option
9981003
fi
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/usr/bin/env zsh
2+
# -------------------------------------------------------------------------------------------------
3+
# Copyright (c) 2018 zsh-syntax-highlighting contributors
4+
# All rights reserved.
5+
#
6+
# Redistribution and use in source and binary forms, with or without modification, are permitted
7+
# provided that the following conditions are met:
8+
#
9+
# * Redistributions of source code must retain the above copyright notice, this list of conditions
10+
# and the following disclaimer.
11+
# * Redistributions in binary form must reproduce the above copyright notice, this list of
12+
# conditions and the following disclaimer in the documentation and/or other materials provided
13+
# with the distribution.
14+
# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors
15+
# may be used to endorse or promote products derived from this software without specific prior
16+
# written permission.
17+
#
18+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
19+
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20+
# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
21+
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22+
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23+
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
24+
# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25+
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+
# -------------------------------------------------------------------------------------------------
27+
# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*-
28+
# vim: ft=zsh sw=2 ts=2 et
29+
# -------------------------------------------------------------------------------------------------
30+
31+
touch -- -n
32+
33+
BUFFER=$'cat -n -- -n | cat -n'
34+
35+
expected_region_highlight=(
36+
'1 3 command' # cat
37+
'5 6 single-hyphen-option' # -n
38+
'8 9 default' # --
39+
'11 12 path' # -n
40+
'14 14 commandseparator' # |
41+
'16 18 command' # cat
42+
'20 21 single-hyphen-option' # -n
43+
)

0 commit comments

Comments
 (0)