zsh-users / zsh-syntax-highlighting

Fish shell like syntax highlighting for Zsh.
github.com/zsh-users/zsh-syntax-highlighting
BSD 3-Clause "New" or "Revised" License
20k stars 1.33k forks source link

FR: Custom patterns using Regex instead of Globbing? #876

Closed chrisgrieser closed 2 years ago

chrisgrieser commented 2 years ago

Not sure whether something like that is already possible – the docs on custom highlight patterns are rather brief – but is it possible to use more advanced pattern matching than globbing, i.e. regex?

So I want to highlight part of the buffer when a git commit messages goes beyond 50 characters.[^1] The best I could come up with is

ZSH_HIGHLIGHT_PATTERNS+=('git commit -m "??????????????????????????????????????????????????' 'fg=red,bold')

... which feels quite janky (using exactly 50 ?) and also only highlights the part not beyond 50 characters: image

The docs do not really elaborate on what can be used aside the globbing pattern in the example. I tested regex in ZSH_HIGHLIGHT_PATTERNS which does not work.

[^1]: Essentially, I am looking for something like this regex: /(?<=git commit -m .{50,}).+/

phy1729 commented 2 years ago

Seems you want the regexp highlighter.

chrisgrieser commented 2 years ago

oh, my bad, I've totally missed that one. 🙈