Compare commits

...

3 Commits

Author SHA1 Message Date
Daniel Shahaf 9cfa7fa35c
Merge c8f5d10dfe into 1d85c69261 2026-02-16 10:30:52 +00:00
Matthew Martin 1d85c69261 main: precommand_options += caffeinate
Closes #975
2026-02-08 10:49:40 -06:00
Daniel Shahaf c8f5d10dfe 'main': Highlight backslash escape sequences outside quotes.
Fixes #631.

WIP: test expectations should be updated (12 failures including cthulhu)
2020-06-08 14:53:28 +00:00
3 changed files with 11 additions and 1 deletions

View File

@ -56,6 +56,7 @@ This highlighter defines the following styles:
* `dollar-quoted-argument-unclosed` - unclosed dollar-quoted arguments (`` $'foo ``)
* `rc-quote` - two single quotes inside single quotes when the `RC_QUOTES` option is set (`` 'foo''bar' ``)
* `dollar-double-quoted-argument` - parameter expansion inside double quotes (`$foo` inside `""`)
* `back-un-quoted-argument` - backslash escape sequences outside quotes (`\"` in `print -r \"bar\"`)
* `back-double-quoted-argument` - backslash escape sequences inside double-quoted arguments (`\"` in `"foo\"bar"`)
* `back-dollar-quoted-argument` - backslash escape sequences inside dollar-quoted arguments (`\x` in `$'\x48'`)
* `assign` - parameter assignments (`x=foo` and `x=( )`)

View File

@ -55,6 +55,7 @@
: ${ZSH_HIGHLIGHT_STYLES[dollar-quoted-argument]:=fg=yellow}
: ${ZSH_HIGHLIGHT_STYLES[rc-quote]:=fg=cyan}
: ${ZSH_HIGHLIGHT_STYLES[dollar-double-quoted-argument]:=fg=cyan}
: ${ZSH_HIGHLIGHT_STYLES[back-un-quoted-argument]:=fg=cyan}
: ${ZSH_HIGHLIGHT_STYLES[back-double-quoted-argument]:=fg=cyan}
: ${ZSH_HIGHLIGHT_STYLES[back-dollar-quoted-argument]:=fg=cyan}
: ${ZSH_HIGHLIGHT_STYLES[assign]:=none}
@ -372,6 +373,7 @@ _zsh_highlight_highlighter_main_paint()
'grc' :se # grc - a "generic colouriser" (that's their spelling, not mine)
'cpulimit' elp:ivz # cpulimit 0.2
'ktrace' fgpt:aBCcdiT
'caffeinate' tw:dimsu # as of macOS's caffeinate(8) dated November 9, 2012
)
# Commands that would need to skip one positional argument:
# flock
@ -1351,7 +1353,13 @@ _zsh_highlight_main_highlighter_highlight_argument()
i=${arg[(ib.i.)[\\\'\"\`\$\<\>\*\?]]}
case "$arg[$i]" in
"") break;;
"\\") (( i += 1 )); continue;;
"\\")
highlights+=(
$(( start_pos + i - 1 )) $((start_pos + i + 1)) back-un-quoted-argument
)
(( i += 1 ))
continue
;;
"'")
_zsh_highlight_main_highlighter_highlight_single_quote $i
(( i = REPLY ))

View File

@ -34,4 +34,5 @@ expected_region_highlight=(
'1 4 builtin' # echo
'6 18 default "issue #705"' # foo\\\nbar"baz"
'14 18 double-quoted-argument "issue #705"' # "baz"
# TODO: when fixing this, see if we can highlight the backslash-newline sequence as a comment.
)