From f39e4bbdfb6a206ed3a1d144d7457abb85f45214 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Sat, 13 Jun 2026 01:11:03 -0400 Subject: [PATCH] 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