You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

108 rivejä
5.0 KiB

6 vuotta sitten
  1. zsh-syntax-highlighting / highlighters / main
  2. ---------------------------------------------
  3. This is the `main` highlighter, that highlights:
  4. * Commands
  5. * Options
  6. * Arguments
  7. * Paths
  8. * Strings
  9. This highlighter is active by default.
  10. ### How to tweak it
  11. This highlighter defines the following styles:
  12. * `unknown-token` - unknown tokens / errors
  13. * `reserved-word` - shell reserved words (`if`, `for`)
  14. * `alias` - aliases
  15. * `suffix-alias` - suffix aliases (requires zsh 5.1.1 or newer)
  16. * `builtin` - shell builtin commands (`shift`, `pwd`, `zstyle`)
  17. * `function` - function names
  18. * `command` - command names
  19. * `precommand` - precommand modifiers (e.g., `noglob`, `builtin`)
  20. * `commandseparator` - command separation tokens (`;`, `&&`)
  21. * `hashed-command` - hashed commands
  22. * `path` - existing filenames
  23. * `path_pathseparator` - path separators in filenames (`/`); if unset, `path` is used (default)
  24. * `path_prefix` - prefixes of existing filenames
  25. * `path_prefix_pathseparator` - path separators in prefixes of existing filenames (`/`); if unset, `path_prefix` is used (default)
  26. * `globbing` - globbing expressions (`*.txt`)
  27. * `history-expansion` - history expansion expressions (`!foo` and `^foo^bar`)
  28. * `command-substitution` - command substitutions (`$(echo foo)`)
  29. * `command-substitution-delimiter` - command substitution delimiters (`$(` and `)`)
  30. * `process-substitution` - process substitutions (`<(echo foo)`)
  31. * `process-substitution-delimiter` - process substitution delimiters (`<(` and `)`)
  32. * `single-hyphen-option` - single-hyphen options (`-o`)
  33. * `double-hyphen-option` - double-hyphen options (`--option`)
  34. * `back-quoted-argument` - backtick command substitution (`` `foo` ``)
  35. * `back-quoted-argument-unclosed` - unclosed backtick command substitution (`` `foo ``)
  36. * `back-quoted-argument-delimiter` - backtick command substitution delimiters (`` ` ``)
  37. * `single-quoted-argument` - single-quoted arguments (`` 'foo' ``)
  38. * `single-quoted-argument-unclosed` - unclosed single-quoted arguments (`` 'foo ``)
  39. * `double-quoted-argument` - double-quoted arguments (`` "foo" ``)
  40. * `double-quoted-argument-unclosed` - unclosed double-quoted arguments (`` "foo ``)
  41. * `dollar-quoted-argument` - dollar-quoted arguments (`` $'foo' ``)
  42. * `dollar-quoted-argument-unclosed` - unclosed dollar-quoted arguments (`` $'foo ``)
  43. * `rc-quote` - two single quotes inside single quotes when the `RC_QUOTES` option is set (`` 'foo''bar' ``)
  44. * `dollar-double-quoted-argument` - parameter expansion inside double quotes (`$foo` inside `""`)
  45. * `back-double-quoted-argument` - backslash escape sequences inside double-quoted arguments (`\"` in `"foo\"bar"`)
  46. * `back-dollar-quoted-argument` - backslash escape sequences inside dollar-quoted arguments (`\x` in `$'\x48'`)
  47. * `assign` - parameter assignments (`x=foo` and `x=( )`)
  48. * `redirection` - redirection operators (`<`, `>`, etc)
  49. * `comment` - comments, when `setopt INTERACTIVE_COMMENTS` is in effect (`echo # foo`)
  50. * `arg0` - a command word other than one of those enumerated above (other than a command, precommand, alias, function, or shell builtin command).
  51. * `default` - everything else
  52. To override one of those styles, change its entry in `ZSH_HIGHLIGHT_STYLES`,
  53. for example in `~/.zshrc`:
  54. # Declare the variable
  55. typeset -A ZSH_HIGHLIGHT_STYLES
  56. # To differentiate aliases from other command types
  57. ZSH_HIGHLIGHT_STYLES[alias]='fg=magenta,bold'
  58. # To have paths colored instead of underlined
  59. ZSH_HIGHLIGHT_STYLES[path]='fg=cyan'
  60. # To disable highlighting of globbing expressions
  61. ZSH_HIGHLIGHT_STYLES[globbing]='none'
  62. The syntax for values is the same as the syntax of "types of highlighting" of
  63. the zsh builtin `$zle_highlight` array, which is documented in [the `zshzle(1)`
  64. manual page][zshzle-Character-Highlighting].
  65. #### Parameters
  66. To avoid partial path lookups on a path, add the path to the `X_ZSH_HIGHLIGHT_DIRS_BLACKLIST` array.
  67. This interface is still experimental.
  68. X_ZSH_HIGHLIGHT_DIRS_BLACKLIST+=(/mnt/slow_share)
  69. ### Useless trivia
  70. #### Forward compatibility.
  71. zsh-syntax-highlighting attempts to be forward-compatible with zsh.
  72. Specifically, we attempt to facilitate highlighting _command word_ types that
  73. had not yet been invented when this version of zsh-syntax-highlighting was
  74. released.
  75. A _command word_ is something like a function name, external command name, et
  76. cetera. (See
  77. [Simple Commands & Pipelines in `zshmisc(1)`][zshmisc-Simple-Commands-And-Pipelines]
  78. for a formal definition.)
  79. If a new _kind_ of command word is ever added to zsh — something conceptually
  80. different than "function" and "alias" and "external command" — then command words
  81. of that (new) kind will be highlighted by the style `arg0_$kind`,
  82. where `$kind` is the output of `type -w` on the new kind of command word. If that
  83. style is not defined, then the style `arg0` will be used instead.
  84. [zshmisc-Simple-Commands-And-Pipelines]: http://zsh.sourceforge.net/Doc/Release/Shell-Grammar.html#Simple-Commands-_0026-Pipelines
  85. [zshzle-Character-Highlighting]: http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting