Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

65 rindas
2.5 KiB

  1. zsh-syntax-highlighting / highlighters / regexp
  2. ------------------------------------------------
  3. This is the `regexp` highlighter, that highlights user-defined regular
  4. expressions. It's similar to the `pattern` highlighter, but allows more complex
  5. patterns.
  6. ### How to tweak it
  7. To use this highlighter, associate regular expressions with styles in the
  8. `ZSH_HIGHLIGHT_REGEXP` associative array, for example in `~/.zshrc`:
  9. ```zsh
  10. typeset -A ZSH_HIGHLIGHT_REGEXP
  11. ZSH_HIGHLIGHT_REGEXP+=('^rm .*' fg=red,bold)
  12. ```
  13. This will highlight lines that start with a call to the `rm` command.
  14. The regular expressions flavour used is [PCRE][pcresyntax] when the
  15. `RE_MATCH_PCRE` option is set and POSIX Extended Regular Expressions (ERE),
  16. as implemented by the platform's C library, otherwise. For details on the
  17. latter, see [the `zsh/regex` module's documentation][MAN_ZSH_REGEX] and the
  18. `regcomp(3)` and `re_format(7)` manual pages on your system.
  19. For instance, to highlight `sudo` only as a complete word, i.e., `sudo cmd`,
  20. but not `sudoedit`, one might use:
  21. * When the `RE_MATCH_PCRE` is set:
  22. ```zsh
  23. typeset -A ZSH_HIGHLIGHT_REGEXP
  24. ZSH_HIGHLIGHT_REGEXP+=('\bsudo\b' fg=123,bold)
  25. ```
  26. * When the `RE_MATCH_PCRE` is unset, on platforms with GNU `libc` (e.g., many GNU/Linux distributions):
  27. ```zsh
  28. typeset -A ZSH_HIGHLIGHT_REGEXP
  29. ZSH_HIGHLIGHT_REGEXP+=('\<sudo\>' fg=123,bold)
  30. ```
  31. * When the `RE_MATCH_PCRE` is unset, on BSD-based platforms (e.g., macOS):
  32. ```zsh
  33. typeset -A ZSH_HIGHLIGHT_REGEXP
  34. ZSH_HIGHLIGHT_REGEXP+=('[[:<:]]sudo[[:>:]]' fg=123,bold)
  35. ```
  36. Note, however, that PCRE and POSIX ERE have a large common subset:
  37. for instance, the regular expressions `[abc]`, `a*`, and `(a|b)` have the same
  38. meaning in both flavours.
  39. The syntax for values is the same as the syntax of "types of highlighting" of
  40. the zsh builtin `$zle_highlight` array, which is documented in [the `zshzle(1)`
  41. manual page][zshzle-Character-Highlighting].
  42. See also: [regular expressions tutorial][perlretut], zsh regexp operator `=~`
  43. in [the `zshmisc(1)` manual page][zshmisc-Conditional-Expressions]
  44. [zshzle-Character-Highlighting]: https://zsh.sourceforge.io/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting
  45. [perlretut]: http://perldoc.perl.org/perlretut.html
  46. [zshmisc-Conditional-Expressions]: https://zsh.sourceforge.io/Doc/Release/Conditional-Expressions.html#Conditional-Expressions
  47. [MAN_ZSH_REGEX]: https://zsh.sourceforge.io/Doc/Release/Zsh-Modules.html#The-zsh_002fregex-Module
  48. [pcresyntax]: https://www.pcre.org/original/doc/html/pcresyntax.html