Skip to content

Commit 90114a3

Browse files
committed
main: Do not highlight options after --
1 parent 565463c commit 90114a3

File tree

2 files changed

+51
-2
lines changed

2 files changed

+51
-2
lines changed

highlighters/main/main-highlighter.zsh

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ _zsh_highlight_highlighter_main_paint()
298298
# exit code is 0 if the braces_stack is empty, 1 otherwise.
299299
_zsh_highlight_main_highlighter_highlight_list()
300300
{
301-
integer start_pos=0 end_pos buf_offset=$1 has_end=$3
301+
integer start_pos=0 end_pos buf_offset=$1 has_end=$3 seen_dashdash=0
302302
local buf=$4 highlight_glob=true arg style
303303
local in_array_assignment=false # true between 'a=(' and the matching ')'
304304
integer len=$#buf
@@ -647,6 +647,7 @@ _zsh_highlight_main_highlighter_highlight_list()
647647
else
648648
style=unknown-token
649649
fi
650+
seen_dashdash=0
650651
elif (( in_redirection == 2 )); then
651652
style=redirection
652653
elif [[ $arg[1,2] == '((' ]]; then
@@ -737,6 +738,7 @@ _zsh_highlight_main_highlighter_highlight_list()
737738
else
738739
style=unknown-token
739740
fi
741+
seen_dashdash=0
740742
elif (( in_redirection == 2 )); then
741743
style=redirection
742744
else
@@ -869,7 +871,11 @@ _zsh_highlight_main_highlighter_highlight_argument()
869871
case "$arg[i]" in
870872
'-')
871873
if [[ $arg[i+1] == - ]]; then
872-
base_style=double-hyphen-option
874+
if [[ $#arg == 2 ]]; then
875+
seen_dashdash=1
876+
else
877+
base_style=double-hyphen-option
878+
fi
873879
else
874880
base_style=single-hyphen-option
875881
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)