25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

105 satır
3.8 KiB

  1. zsh-syntax-highlighting / highlighters
  2. ======================================
  3. Syntax highlighting is done by pluggable highlighters:
  4. * `main` - the base highlighter, and the only one [active by default][1].
  5. * `brackets` - [matches brackets][2] and parenthesis.
  6. * `pattern` - matches [user-defined patterns][3].
  7. * `cursor` - matches [the cursor position][4].
  8. * `root` - highlights the whole command line [if the current user is root][5].
  9. * `line` - applied to [the whole command line][6].
  10. [1]: highlighters/main.md
  11. [2]: highlighters/brackets.md
  12. [3]: highlighters/pattern.md
  13. [4]: highlighters/cursor.md
  14. [5]: highlighters/root.md
  15. [6]: highlighters/line.md
  16. How to activate highlighters
  17. ----------------------------
  18. To activate an highlighter, add it to the `ZSH_HIGHLIGHT_HIGHLIGHTERS` array in
  19. `~/.zshrc`, for example:
  20. ZSH_HIGHLIGHT_HIGHLIGHTERS=(main brackets pattern cursor)
  21. By default, `$ZSH_HIGHLIGHT_HIGHLIGHTERS` is unset and only the `main`
  22. highlighter is active.
  23. How to tweak highlighters
  24. -------------------------
  25. Highlighters look up styles from the `ZSH_HIGHLIGHT_STYLES` associative array.
  26. Navigate into the [individual highlighters' documentation](highlighters/) to
  27. see what styles (keys) each highlighter defines; the syntax for values is the
  28. same as the syntax of "types of highlighting" of the zsh builtin
  29. `$zle_highlight` array, which is documented in [the `zshzle(1)` manual
  30. page][zshzle-Character-Highlighting].
  31. [zshzle-Character-Highlighting]: http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting
  32. Some highlighters support additional configuration parameters; see each
  33. highlighter's documentation for details and examples.
  34. How to implement a new highlighter
  35. ----------------------------------
  36. To create your own `acme` highlighter:
  37. * Create your script at
  38. `highlighters/acme/acme-highlighter.zsh`.
  39. * Implement the `_zsh_highlight_highlighter_acme_predicate` function.
  40. This function must return 0 when the highlighter needs to be called and
  41. non-zero otherwise, for example:
  42. _zsh_highlight_highlighter_acme_predicate() {
  43. # Call this highlighter in SVN working copies
  44. [[ -d .svn ]]
  45. }
  46. * Implement the `_zsh_highlight_highlighter_acme_paint` function.
  47. This function does the actual syntax highlighting, by calling
  48. `_zsh_highlight_add_highlight` with the start and end of the region to
  49. be highlighted and the `ZSH_HIGHLIGHT_STYLES` key to use. Define the default
  50. style for that key in the highlighter script outside of any function with
  51. `: ${ZSH_HIGHLIGHT_STYLES[key]:=value}`, being sure to prefix
  52. the key with your highlighter name and a colon. For example:
  53. : ${ZSH_HIGHLIGHT_STYLES[acme:aurora]:=fg=green}
  54. _zsh_highlight_highlighter_acme_paint() {
  55. # Colorize the whole buffer with the 'aurora' style
  56. _zsh_highlight_add_highlight 0 $#BUFFER acme:aurora
  57. }
  58. If you need to test which options the user has set, test `zsyh_user_options`
  59. with a sensible default if the option is not present in supported zsh
  60. versions. For example:
  61. [[ ${zsyh_user_options[ignoreclosebraces]:-off} == on ]]
  62. The option name must be all lowercase with no underscores and not an alias.
  63. * Name your own functions and global variables `_zsh_highlight_acme_*`.
  64. - In zsh-syntax-highlighting 0.4.0 and earlier, the entrypoints
  65. `_zsh_highlight_highlighter_acme_predicate` and
  66. `_zsh_highlight_highlighter_acme_paint`
  67. were named
  68. `_zsh_highlight_acme_highlighter_predicate` and
  69. `_zsh_highlight_highlighter_acme_paint` respectively.
  70. These names are still supported for backwards compatibility;
  71. however, support for them will be removed in a a future major or minor release (v0.x.0 or v1.0.0).
  72. * Activate your highlighter in `~/.zshrc`:
  73. ZSH_HIGHLIGHT_HIGHLIGHTERS+=(acme)
  74. * [Write tests](../tests/README.md).