Issue 17: Update README with "How to override the default styles"

Harmonize variable names
This commit is contained in:
Julien Nicoulaud 2011-01-01 17:34:35 +01:00
parent e50d47ae1b
commit 90e661bd69
2 changed files with 77 additions and 62 deletions

View File

@ -1,61 +1,77 @@
zsh-syntax-highlighting
=======================
An attempt at providing [Fish shell](http://www.fishshell.org) like syntax highlighting for [Zsh](http://www.zsh.org).
[Fish shell](http://www.fishshell.org) like syntax highlighting for [Zsh](http://www.zsh.org).
## Usage
## Try it
Here is a one-liner to try it without installing or modifying anything:
wget --no-check-certificate --output-document=/tmp/zsh-syntax-highlighting.zsh https://github.com/nicoulaj/zsh-syntax-highlighting/raw/master/zsh-syntax-highlighting.zsh && . /tmp/zsh-syntax-highlighting.zsh
### From your ~/.zshrc
## Install it
Download the script or clone this repository:
### In your ~/.zshrc
* Download the script or clone this repository:
git clone git://github.com/nicoulaj/zsh-syntax-highlighting.git
Update your `~/.zshrc` so that the script is sourced:
* Source the script at the end of `~/.zshrc`:
source /path/to/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
Re-open your terminal, or just reload it to take changes into account:
* Source `~/.zshrc` to take changes into account:
source ~/.zshrc
### With [oh-my-zsh](http://github.com/robbyrussell/oh-my-zsh)
### With oh-my-zsh
Download the script or clone this repository as a oh-my-zsh plugin:
* Download the script or clone this repository in [oh-my-zsh](http://github.com/robbyrussell/oh-my-zsh) plugins directory:
cd ~/.oh-my-zsh/plugins/
git clone git://github.com/nicoulaj/zsh-syntax-highlighting.git
cd zsh-syntax-highlighting
ln -s zsh-syntax-highlighting.zsh zsh-syntax-highlighting.plugin.zsh
Update your `~/.zshrc` so that the script is sourced:
* Activate the plugin in `~/.zshrc`
plugins=(zsh-syntax-highlighting)
Re-open your terminal, or just reload it to take changes into account:
* Source `~/.zshrc` to take changes into account:
source ~/.zshrc
## References
## Tweak it
* [zsh-users mailing list thread](http://www.zsh.org/mla/users/2010/msg00692.html)
* [Gist 586698](http://gist.github.com/586698) and forks
Optionally, you can override the default styles used for highlighting. The styles are declared in the [`ZSH_HIGHLIGHT_STYLES` array](https://github.com/nicoulaj/zsh-syntax-highlighting/blob/master/zsh-syntax-highlighting.zsh#L9). You can override styles this way:
# To differenciate aliases from other command types
ZSH_HIGHLIGHT_STYLES[alias]='fg=magenta,bold'
# To have paths colored instead of underlined
ZSH_HIGHLIGHT_STYLES[path]='fg=cyan'
# To disable highlighting of globbing expressions
ZSH_HIGHLIGHT_STYLES[globbing]='none'
This must be done **after** the script is sourced, otherwise your styles will be overwritten. The syntax for declaring styles is [documented here](http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#SEC135).
## Authors / Greetings
* [Roy Zuo](http://github.com/roylez)
* [Julien Nicoulaud](http://github.com/nicoulaj)
* [Dave Ingram](http://github.com/dingram)
* [Mounier Florian](http://github.com/paradoxxxzero)
* [Jonathan Dahan](http://github.com/jedahan)
* [Roy Zuo](https://github.com/roylez)
* [Julien Nicoulaud](https://github.com/nicoulaj)
* [Dave Ingram](https://github.com/dingram)
* [Mounier Florian](https://github.com/paradoxxxzero)
* [Jonathan Dahan](https://github.com/jedahan)
* James Ahlborn
* [Andreas Jaggi](http://github.com/x-way)
* [Wayne Davison](http://github.com/WayneD)
* [Suraj N. Kurapati](http://github.com/sunaku)
* [Takeshi Banse](http://github.com/hchbaw)
* [Andreas Jaggi](https://github.com/x-way)
* [Wayne Davison](https://github.com/WayneD)
* [Suraj N. Kurapati](https://github.com/sunaku)
* [Takeshi Banse](https://github.com/hchbaw)

View File

@ -5,9 +5,8 @@
# vim: ft=zsh sw=2 ts=2 et
# Token types styles.
# See http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#SEC135
typeset -A ZSH_SYNTAX_HIGHLIGHTING_STYLES
ZSH_SYNTAX_HIGHLIGHTING_STYLES=(
typeset -A ZSH_HIGHLIGHT_STYLES
ZSH_HIGHLIGHT_STYLES=(
default 'none'
isearch 'fg=magenta,standout'
special 'fg=magenta,standout'
@ -103,8 +102,8 @@ ZSH_HIGHLIGHT_ZLE_UPDATE_EVENTS=(
# ZLE highlight types.
zle_highlight=(
special:$ZSH_SYNTAX_HIGHLIGHTING_STYLES[special]
isearch:$ZSH_SYNTAX_HIGHLIGHTING_STYLES[isearch]
special:$ZSH_HIGHLIGHT_STYLES[special]
isearch:$ZSH_HIGHLIGHT_STYLES[isearch]
)
# Check if the argument is a path.
@ -125,8 +124,8 @@ _zsh_highlight-string() {
(( j = i + start_pos - 1 ))
(( k = j + 1 ))
case "$arg[$i]" in
'$') style=$ZSH_SYNTAX_HIGHLIGHTING_STYLES[dollar-double-quoted-argument];;
"\\") style=$ZSH_SYNTAX_HIGHLIGHTING_STYLES[back-double-quoted-argument]
'$') style=$ZSH_HIGHLIGHT_STYLES[dollar-double-quoted-argument];;
"\\") style=$ZSH_HIGHLIGHT_STYLES[back-double-quoted-argument]
(( k += 1 )) # Color following char too.
(( i += 1 )) # Skip parsing the escaped char.
;;
@ -157,42 +156,42 @@ _zsh_highlight-zle-buffer() {
new_expression=false
res=$(LC_ALL=C builtin type -w $arg 2>/dev/null)
case $res in
*': reserved') style=$ZSH_SYNTAX_HIGHLIGHTING_STYLES[reserved-word];;
*': alias') style=$ZSH_SYNTAX_HIGHLIGHTING_STYLES[alias]
*': reserved') style=$ZSH_HIGHLIGHT_STYLES[reserved-word];;
*': alias') style=$ZSH_HIGHLIGHT_STYLES[alias]
local aliased_command=${"$(alias $arg)"#*=}
if [[ ${${ZSH_HIGHLIGHT_TOKENS_FOLLOWED_BY_COMMANDS[(r)$aliased_command]:-}:+yes} = 'yes' && ${${ZSH_HIGHLIGHT_TOKENS_FOLLOWED_BY_COMMANDS[(r)$arg]:-}:+yes} != 'yes' ]]; then
ZSH_HIGHLIGHT_TOKENS_FOLLOWED_BY_COMMANDS+=($arg)
fi
;;
*': builtin') style=$ZSH_SYNTAX_HIGHLIGHTING_STYLES[builtin];;
*': function') style=$ZSH_SYNTAX_HIGHLIGHTING_STYLES[function];;
*': command') style=$ZSH_SYNTAX_HIGHLIGHTING_STYLES[command];;
*': builtin') style=$ZSH_HIGHLIGHT_STYLES[builtin];;
*': function') style=$ZSH_HIGHLIGHT_STYLES[function];;
*': command') style=$ZSH_HIGHLIGHT_STYLES[command];;
*) if _zsh_check-path; then
style=$ZSH_SYNTAX_HIGHLIGHTING_STYLES[path]
style=$ZSH_HIGHLIGHT_STYLES[path]
elif [[ ${arg:0:1} = ${histchars:0:1} ]]; then
style=$ZSH_SYNTAX_HIGHLIGHTING_STYLES[history-expansion]
style=$ZSH_HIGHLIGHT_STYLES[history-expansion]
else
style=$ZSH_SYNTAX_HIGHLIGHTING_STYLES[unknown-token]
style=$ZSH_HIGHLIGHT_STYLES[unknown-token]
fi;;
esac
else
case $arg in
'--'*) style=$ZSH_SYNTAX_HIGHLIGHTING_STYLES[double-hyphen-option];;
'-'*) style=$ZSH_SYNTAX_HIGHLIGHTING_STYLES[single-hyphen-option];;
"'"*"'") style=$ZSH_SYNTAX_HIGHLIGHTING_STYLES[single-quoted-argument];;
'"'*'"') style=$ZSH_SYNTAX_HIGHLIGHTING_STYLES[double-quoted-argument]
'--'*) style=$ZSH_HIGHLIGHT_STYLES[double-hyphen-option];;
'-'*) style=$ZSH_HIGHLIGHT_STYLES[single-hyphen-option];;
"'"*"'") style=$ZSH_HIGHLIGHT_STYLES[single-quoted-argument];;
'"'*'"') style=$ZSH_HIGHLIGHT_STYLES[double-quoted-argument]
region_highlight+=("$start_pos $end_pos $style")
_zsh_highlight-string
substr_color=1
;;
'`'*'`') style=$ZSH_SYNTAX_HIGHLIGHTING_STYLES[back-quoted-argument];;
*"*"*) $highlight_glob && style=$ZSH_SYNTAX_HIGHLIGHTING_STYLES[globbing] || style=$ZSH_SYNTAX_HIGHLIGHTING_STYLES[default];;
'`'*'`') style=$ZSH_HIGHLIGHT_STYLES[back-quoted-argument];;
*"*"*) $highlight_glob && style=$ZSH_HIGHLIGHT_STYLES[globbing] || style=$ZSH_HIGHLIGHT_STYLES[default];;
*) if _zsh_check-path; then
style=$ZSH_SYNTAX_HIGHLIGHTING_STYLES[path]
style=$ZSH_HIGHLIGHT_STYLES[path]
elif [[ ${arg:0:1} = ${histchars:0:1} ]]; then
style=$ZSH_SYNTAX_HIGHLIGHTING_STYLES[history-expansion]
style=$ZSH_HIGHLIGHT_STYLES[history-expansion]
else
style=$ZSH_SYNTAX_HIGHLIGHTING_STYLES[default]
style=$ZSH_HIGHLIGHT_STYLES[default]
fi;;
esac
fi