Issue 17: Update README with "How to override the default styles"
Harmonize variable names
This commit is contained in:
parent
e50d47ae1b
commit
90e661bd69
92
README.md
92
README.md
@ -1,61 +1,77 @@
|
|||||||
zsh-syntax-highlighting
|
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:
|
|
||||||
|
|
||||||
git clone git://github.com/nicoulaj/zsh-syntax-highlighting.git
|
|
||||||
|
|
||||||
Update your `~/.zshrc` so that the script is sourced:
|
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
|
|
||||||
### With [oh-my-zsh](http://github.com/robbyrussell/oh-my-zsh)
|
### In your ~/.zshrc
|
||||||
|
|
||||||
Download the script or clone this repository as a oh-my-zsh plugin:
|
* Download the script or clone this repository:
|
||||||
|
|
||||||
cd ~/.oh-my-zsh/plugins/
|
git clone git://github.com/nicoulaj/zsh-syntax-highlighting.git
|
||||||
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:
|
* Source the script at the end of `~/.zshrc`:
|
||||||
|
|
||||||
plugins=(zsh-syntax-highlighting)
|
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
|
||||||
|
|
||||||
|
* 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
|
||||||
|
|
||||||
|
* Activate the plugin in `~/.zshrc`
|
||||||
|
|
||||||
|
plugins=(zsh-syntax-highlighting)
|
||||||
|
|
||||||
|
* Source `~/.zshrc` to take changes into account:
|
||||||
|
|
||||||
source ~/.zshrc
|
source ~/.zshrc
|
||||||
|
|
||||||
|
|
||||||
## References
|
## Tweak it
|
||||||
|
|
||||||
* [zsh-users mailing list thread](http://www.zsh.org/mla/users/2010/msg00692.html)
|
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:
|
||||||
* [Gist 586698](http://gist.github.com/586698) and forks
|
|
||||||
|
# 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
|
## Authors / Greetings
|
||||||
|
|
||||||
* [Roy Zuo](http://github.com/roylez)
|
* [Roy Zuo](https://github.com/roylez)
|
||||||
* [Julien Nicoulaud](http://github.com/nicoulaj)
|
* [Julien Nicoulaud](https://github.com/nicoulaj)
|
||||||
* [Dave Ingram](http://github.com/dingram)
|
* [Dave Ingram](https://github.com/dingram)
|
||||||
* [Mounier Florian](http://github.com/paradoxxxzero)
|
* [Mounier Florian](https://github.com/paradoxxxzero)
|
||||||
* [Jonathan Dahan](http://github.com/jedahan)
|
* [Jonathan Dahan](https://github.com/jedahan)
|
||||||
* James Ahlborn
|
* James Ahlborn
|
||||||
* [Andreas Jaggi](http://github.com/x-way)
|
* [Andreas Jaggi](https://github.com/x-way)
|
||||||
* [Wayne Davison](http://github.com/WayneD)
|
* [Wayne Davison](https://github.com/WayneD)
|
||||||
* [Suraj N. Kurapati](http://github.com/sunaku)
|
* [Suraj N. Kurapati](https://github.com/sunaku)
|
||||||
* [Takeshi Banse](http://github.com/hchbaw)
|
* [Takeshi Banse](https://github.com/hchbaw)
|
||||||
|
|
||||||
|
@ -5,9 +5,8 @@
|
|||||||
# vim: ft=zsh sw=2 ts=2 et
|
# vim: ft=zsh sw=2 ts=2 et
|
||||||
|
|
||||||
# Token types styles.
|
# Token types styles.
|
||||||
# See http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#SEC135
|
typeset -A ZSH_HIGHLIGHT_STYLES
|
||||||
typeset -A ZSH_SYNTAX_HIGHLIGHTING_STYLES
|
ZSH_HIGHLIGHT_STYLES=(
|
||||||
ZSH_SYNTAX_HIGHLIGHTING_STYLES=(
|
|
||||||
default 'none'
|
default 'none'
|
||||||
isearch 'fg=magenta,standout'
|
isearch 'fg=magenta,standout'
|
||||||
special 'fg=magenta,standout'
|
special 'fg=magenta,standout'
|
||||||
@ -103,8 +102,8 @@ ZSH_HIGHLIGHT_ZLE_UPDATE_EVENTS=(
|
|||||||
|
|
||||||
# ZLE highlight types.
|
# ZLE highlight types.
|
||||||
zle_highlight=(
|
zle_highlight=(
|
||||||
special:$ZSH_SYNTAX_HIGHLIGHTING_STYLES[special]
|
special:$ZSH_HIGHLIGHT_STYLES[special]
|
||||||
isearch:$ZSH_SYNTAX_HIGHLIGHTING_STYLES[isearch]
|
isearch:$ZSH_HIGHLIGHT_STYLES[isearch]
|
||||||
)
|
)
|
||||||
|
|
||||||
# Check if the argument is a path.
|
# Check if the argument is a path.
|
||||||
@ -125,8 +124,8 @@ _zsh_highlight-string() {
|
|||||||
(( j = i + start_pos - 1 ))
|
(( j = i + start_pos - 1 ))
|
||||||
(( k = j + 1 ))
|
(( k = j + 1 ))
|
||||||
case "$arg[$i]" in
|
case "$arg[$i]" in
|
||||||
'$') style=$ZSH_SYNTAX_HIGHLIGHTING_STYLES[dollar-double-quoted-argument];;
|
'$') style=$ZSH_HIGHLIGHT_STYLES[dollar-double-quoted-argument];;
|
||||||
"\\") style=$ZSH_SYNTAX_HIGHLIGHTING_STYLES[back-double-quoted-argument]
|
"\\") style=$ZSH_HIGHLIGHT_STYLES[back-double-quoted-argument]
|
||||||
(( k += 1 )) # Color following char too.
|
(( k += 1 )) # Color following char too.
|
||||||
(( i += 1 )) # Skip parsing the escaped char.
|
(( i += 1 )) # Skip parsing the escaped char.
|
||||||
;;
|
;;
|
||||||
@ -157,42 +156,42 @@ _zsh_highlight-zle-buffer() {
|
|||||||
new_expression=false
|
new_expression=false
|
||||||
res=$(LC_ALL=C builtin type -w $arg 2>/dev/null)
|
res=$(LC_ALL=C builtin type -w $arg 2>/dev/null)
|
||||||
case $res in
|
case $res in
|
||||||
*': reserved') style=$ZSH_SYNTAX_HIGHLIGHTING_STYLES[reserved-word];;
|
*': reserved') style=$ZSH_HIGHLIGHT_STYLES[reserved-word];;
|
||||||
*': alias') style=$ZSH_SYNTAX_HIGHLIGHTING_STYLES[alias]
|
*': alias') style=$ZSH_HIGHLIGHT_STYLES[alias]
|
||||||
local aliased_command=${"$(alias $arg)"#*=}
|
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
|
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)
|
ZSH_HIGHLIGHT_TOKENS_FOLLOWED_BY_COMMANDS+=($arg)
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
*': builtin') style=$ZSH_SYNTAX_HIGHLIGHTING_STYLES[builtin];;
|
*': builtin') style=$ZSH_HIGHLIGHT_STYLES[builtin];;
|
||||||
*': function') style=$ZSH_SYNTAX_HIGHLIGHTING_STYLES[function];;
|
*': function') style=$ZSH_HIGHLIGHT_STYLES[function];;
|
||||||
*': command') style=$ZSH_SYNTAX_HIGHLIGHTING_STYLES[command];;
|
*': command') style=$ZSH_HIGHLIGHT_STYLES[command];;
|
||||||
*) if _zsh_check-path; then
|
*) if _zsh_check-path; then
|
||||||
style=$ZSH_SYNTAX_HIGHLIGHTING_STYLES[path]
|
style=$ZSH_HIGHLIGHT_STYLES[path]
|
||||||
elif [[ ${arg:0:1} = ${histchars:0:1} ]]; then
|
elif [[ ${arg:0:1} = ${histchars:0:1} ]]; then
|
||||||
style=$ZSH_SYNTAX_HIGHLIGHTING_STYLES[history-expansion]
|
style=$ZSH_HIGHLIGHT_STYLES[history-expansion]
|
||||||
else
|
else
|
||||||
style=$ZSH_SYNTAX_HIGHLIGHTING_STYLES[unknown-token]
|
style=$ZSH_HIGHLIGHT_STYLES[unknown-token]
|
||||||
fi;;
|
fi;;
|
||||||
esac
|
esac
|
||||||
else
|
else
|
||||||
case $arg in
|
case $arg in
|
||||||
'--'*) style=$ZSH_SYNTAX_HIGHLIGHTING_STYLES[double-hyphen-option];;
|
'--'*) style=$ZSH_HIGHLIGHT_STYLES[double-hyphen-option];;
|
||||||
'-'*) style=$ZSH_SYNTAX_HIGHLIGHTING_STYLES[single-hyphen-option];;
|
'-'*) style=$ZSH_HIGHLIGHT_STYLES[single-hyphen-option];;
|
||||||
"'"*"'") style=$ZSH_SYNTAX_HIGHLIGHTING_STYLES[single-quoted-argument];;
|
"'"*"'") style=$ZSH_HIGHLIGHT_STYLES[single-quoted-argument];;
|
||||||
'"'*'"') style=$ZSH_SYNTAX_HIGHLIGHTING_STYLES[double-quoted-argument]
|
'"'*'"') style=$ZSH_HIGHLIGHT_STYLES[double-quoted-argument]
|
||||||
region_highlight+=("$start_pos $end_pos $style")
|
region_highlight+=("$start_pos $end_pos $style")
|
||||||
_zsh_highlight-string
|
_zsh_highlight-string
|
||||||
substr_color=1
|
substr_color=1
|
||||||
;;
|
;;
|
||||||
'`'*'`') style=$ZSH_SYNTAX_HIGHLIGHTING_STYLES[back-quoted-argument];;
|
'`'*'`') style=$ZSH_HIGHLIGHT_STYLES[back-quoted-argument];;
|
||||||
*"*"*) $highlight_glob && style=$ZSH_SYNTAX_HIGHLIGHTING_STYLES[globbing] || style=$ZSH_SYNTAX_HIGHLIGHTING_STYLES[default];;
|
*"*"*) $highlight_glob && style=$ZSH_HIGHLIGHT_STYLES[globbing] || style=$ZSH_HIGHLIGHT_STYLES[default];;
|
||||||
*) if _zsh_check-path; then
|
*) if _zsh_check-path; then
|
||||||
style=$ZSH_SYNTAX_HIGHLIGHTING_STYLES[path]
|
style=$ZSH_HIGHLIGHT_STYLES[path]
|
||||||
elif [[ ${arg:0:1} = ${histchars:0:1} ]]; then
|
elif [[ ${arg:0:1} = ${histchars:0:1} ]]; then
|
||||||
style=$ZSH_SYNTAX_HIGHLIGHTING_STYLES[history-expansion]
|
style=$ZSH_HIGHLIGHT_STYLES[history-expansion]
|
||||||
else
|
else
|
||||||
style=$ZSH_SYNTAX_HIGHLIGHTING_STYLES[default]
|
style=$ZSH_HIGHLIGHT_STYLES[default]
|
||||||
fi;;
|
fi;;
|
||||||
esac
|
esac
|
||||||
fi
|
fi
|
||||||
|
Loading…
Reference in New Issue
Block a user