From 99680ff6950ce0861f94851f611fb0d5c5870276 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Sat, 13 Jun 2026 01:10:42 -0400 Subject: [PATCH 1/2] main: highlight redirection targets as paths --- changelog.md | 1 + highlighters/main/main-highlighter.zsh | 3 +++ 2 files changed, 4 insertions(+) diff --git a/changelog.md b/changelog.md index 8ee5088..a2230cd 100644 --- a/changelog.md +++ b/changelog.md @@ -3,6 +3,7 @@ - Highlight `&>` `>&|` `>&!` `&>|` and `&>!` as redirection. [#942] +- Highlight redirection targets as paths if possible [#982]. # Changes in 0.8.0 diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index e6f5e35..095dbe1 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -1441,6 +1441,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 From f39e4bbdfb6a206ed3a1d144d7457abb85f45214 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Sat, 13 Jun 2026 01:11:03 -0400 Subject: [PATCH 2/2] 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 --- changelog.md | 4 ++++ docs/highlighters/main.md | 5 +++++ highlighters/main/main-highlighter.zsh | 10 ++++++++++ 3 files changed, 19 insertions(+) diff --git a/changelog.md b/changelog.md index a2230cd..6766b4a 100644 --- a/changelog.md +++ b/changelog.md @@ -5,6 +5,10 @@ [#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 diff --git a/docs/highlighters/main.md b/docs/highlighters/main.md index 4a27653..eeaa86c 100644 --- a/docs/highlighters/main.md +++ b/docs/highlighters/main.md @@ -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`: diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 095dbe1..d985f7e 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -1258,6 +1258,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