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.

121 lines
5.7 KiB

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