Skip to content

Commit 461684b

Browse files
committed
main: Add ' helper function
1 parent 2b24a39 commit 461684b

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

docs/highlighters/main.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ This highlighter defines the following styles:
3838
* `single-quoted-argument` - single quoted arguments (`` 'foo' ``)
3939
* `double-quoted-argument` - double quoted arguments (`` "foo" ``)
4040
* `dollar-quoted-argument` - dollar quoted arguments (`` $'foo' ``)
41+
* `rc-quote` - two single quotes inside single quotes when `RC_QUOTES` is set (`` 'foo''bar' ``)
4142
* `dollar-double-quoted-argument` - parameter expansion inside double quotes (`$foo` inside `""`)
4243
* `back-double-quoted-argument` - back double quoted arguments (`\x` inside `""`)
4344
* `back-dollar-quoted-argument` - back dollar quoted arguments (`\x` inside `$''`)

highlighters/main/main-highlighter.zsh

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
: ${ZSH_HIGHLIGHT_STYLES[single-quoted-argument]:=fg=yellow}
4747
: ${ZSH_HIGHLIGHT_STYLES[double-quoted-argument]:=fg=yellow}
4848
: ${ZSH_HIGHLIGHT_STYLES[dollar-quoted-argument]:=fg=yellow}
49+
: ${ZSH_HIGHLIGHT_STYLES[rc-quote]:=fg=cyan}
4950
: ${ZSH_HIGHLIGHT_STYLES[dollar-double-quoted-argument]:=fg=cyan}
5051
: ${ZSH_HIGHLIGHT_STYLES[back-double-quoted-argument]:=fg=cyan}
5152
: ${ZSH_HIGHLIGHT_STYLES[back-dollar-quoted-argument]:=fg=cyan}
@@ -670,7 +671,9 @@ _zsh_highlight_highlighter_main_paint()
670671
;|
671672
'--'*) style=double-hyphen-option;;
672673
'-'*) style=single-hyphen-option;;
673-
"'"*) style=single-quoted-argument;;
674+
"'"*) _zsh_highlight_main_highlighter_highlight_single_quote 1
675+
already_added=1
676+
;;
674677
'"'*) _zsh_highlight_main_highlighter_highlight_double_quote
675678
already_added=1
676679
;;
@@ -797,6 +800,25 @@ _zsh_highlight_main_highlighter_check_path()
797800
return 1
798801
}
799802

803+
# Highlight single-quoted strings
804+
_zsh_highlight_main_highlighter_highlight_single_quote()
805+
{
806+
local arg1=$1 i q=\'
807+
local -a highlights
808+
i=$arg[(ib:arg1+1:)$q]
809+
810+
if [[ $useroptions[rcquotes] == on ]]; then
811+
while [[ $arg[i+1] == "'" ]]; do
812+
highlights+=($(( start_pos + i - 1 )) $(( start_pos + ++i )) rc-quote)
813+
i=$arg[(ib:i+1:)$q]
814+
done
815+
fi
816+
817+
highlights+=($(( start_pos + $1 - 1 )) $(( start_pos + i )) single-quoted-argument $highlights)
818+
_zsh_highlight_main_add_region_highlights $highlights
819+
REPLY=$i
820+
}
821+
800822
# Highlight special chars inside double-quoted strings
801823
_zsh_highlight_main_highlighter_highlight_double_quote()
802824
{

0 commit comments

Comments
 (0)