Compare commits

...

4 Commits

Author SHA1 Message Date
Ben Boeckel 9935185d78
Merge f39e4bbdfb into 2fc57d6306 2026-08-22 09:20:15 +07:00
Manish Tiwari 2fc57d6306 tests: fix relative links in tests/README.md
test-highlighting.zsh and test-perfs.zsh were linked as tests/test-*.zsh,
but this file already lives in tests/, so the links resolved to
tests/tests/test-*.zsh and 404'd. Found by pointing a markdown
link-checker at the repo.
2026-08-21 21:19:05 -05:00
Ben Boeckel f39e4bbdfb main: support highlighting paths with specific styles
If there are styles starting with `*.`, consider these "glob matchers"
and style according to the matching glob. This allows users to color
paths matching patterns in any way desired.

Fixes: #605
2026-06-13 01:23:22 -04:00
Ben Boeckel 99680ff695 main: highlight redirection targets as paths 2026-06-13 01:23:22 -04:00
4 changed files with 25 additions and 2 deletions

View File

@ -3,7 +3,12 @@
- Highlight `&>` `>&|` `>&!` `&>|` and `&>!` as redirection.
[#942]
- Highlight redirection targets as paths if possible [#982].
## Highlight paths with matching patterns
When matchers start with `*.`, the are treated as globs to further refine thee
highlighting of paths [#982].
# Changes in 0.8.0

View File

@ -67,6 +67,11 @@ This highlighter defines the following styles:
* `arg0` - a command word other than one of those enumerated above (other than a command, precommand, alias, function, or shell builtin command).
* `default` - everything else
Additionally, styles starting with `*.` may be used to style `path` and
`redirection` argument matches with a more specific style. For example,
defining the `*.png` style will apply to any `path` or `redirection` target
ending with `.png`.
To override one of those styles, change its entry in `ZSH_HIGHLIGHT_STYLES`,
for example in `~/.zshrc`:

View File

@ -1259,6 +1259,16 @@ _zsh_highlight_main_highlighter_check_path()
fi
else
if [[ -L $expanded_path || -e $expanded_path ]]; then
for key in ${(k)ZSH_HIGHLIGHT_STYLES}; do
case $key in
"*."*) ;;
*) continue ;;
esac
case $arg in
*.$key[3,-1]) REPLY=$key ;;
esac
done
return 0
fi
fi
@ -1442,6 +1452,9 @@ _zsh_highlight_main_highlighter_highlight_argument()
if (( in_redirection )) && [[ $last_arg == *['<>']['&'] && $arg[$1,-1] == (<0->|p|-) ]]; then
if [[ $arg[$1,-1] == (p|-) ]]; then
base_style=redirection
if _zsh_highlight_main_highlighter_check_path $arg[$1,-1] 0; then
base_style=$REPLY
fi
else
base_style=numeric-fd
fi

View File

@ -86,7 +86,7 @@ grow ways to set `$PREBUFFER` to inject free-form code into the generated file.
Highlighting test
-----------------
[`test-highlighting.zsh`](tests/test-highlighting.zsh) tests the correctness of
[`test-highlighting.zsh`](test-highlighting.zsh) tests the correctness of
the highlighting. Usage:
```zsh
@ -110,7 +110,7 @@ results (tests that failed but were expected to succeed, or vice-versa), run
Performance test
----------------
[`test-perfs.zsh`](tests/test-perfs.zsh) measures the time spent doing the
[`test-perfs.zsh`](test-perfs.zsh) measures the time spent doing the
highlighting. Usage:
```zsh