24 Commits
0.1.0 ... 0.2.0

Author SHA1 Message Date
Julien Nicoulaud
dbd27cb30a #155: document path_prefix/path_approx 2013-08-09 09:56:28 +02:00
Julien Nicoulaud
08b80022ca Merge pull request #123 from Shura0/master
Highlighted dollar variable ver. 2
2013-08-09 00:47:32 -07:00
Shura
a7ee0597ef Update main-highlighter.zsh
Comments added
2013-08-09 10:24:14 +04:00
Julien Nicoulaud
3677b75731 Merge pull request #115 from Valodim/master
add separate path_prefix and path_approx hilights
2013-08-08 07:31:46 -07:00
Julien Nicoulaud
3f2c76f393 Merge pull request #116 from jameskyle/feature/Issue-#92-silence-system-bell-in-osx
Issue #92 Eliminates system bell errors on osx.
2013-08-08 07:26:22 -07:00
Julien Nicoulaud
6fcdb06b28 Merge pull request #122 from shockone/master
Update main-highlighter.zsh
2013-08-08 07:25:54 -07:00
Владимир
57c01d19de Update main-highlighter.zsh
Add support of CDPATH
2013-08-07 03:21:15 +03:00
Shura
8abcf187f6 dollar variable and backslash codes highlighting 2013-07-29 17:33:34 +04:00
James Kyle
93827ed84d Issue #92 Eliminates system bell errors on osx.
Prepended an 'if' to remove error bell on osx systems.
2013-07-25 11:39:21 -07:00
Vincent Breitmoser
228f5a6aad add separate path_prefix and path_approx hilights 2013-07-25 04:41:09 +02:00
Julien Nicoulaud
e5d8a50d36 Merge pull request #106 from cknadler/master
Fix relative links in various project readmes
2013-02-27 04:42:09 -08:00
Chris Knadler
612e493cba Fix relative links in highlighters readme 2013-02-26 18:03:35 -08:00
Chris Knadler
408b100295 Fix relative link in main readme 2013-02-26 17:59:53 -08:00
Julien Nicoulaud
a0862053f5 Merge pull request #100 from hchbaw/for-nicoulaj/pattern-local
make $pattern local to _zsh_highlight_pattern_highlighter #97
2012-12-19 10:30:06 -08:00
Takeshi Banse
b4e667795c make $pattern local to _zsh_highlight_pattern_highlighter #97
Signed-off-by: Takeshi Banse <takebi@laafc.net>
2012-12-09 10:43:00 +09:00
Julien Nicoulaud
45194671af Merge pull request #91 from xaocon/master
Added sudo as a precommand
2012-08-26 03:33:34 -07:00
evan
19981ef9ea added sudo as a precommand 2012-08-17 15:52:09 -04:00
Jan M. Binder
732b7d6e65 Fix bracket highlighter 2012-04-07 17:09:15 +02:00
Jan M. Binder
966eb851ca Added quotes to suppress error 2012-04-07 11:48:11 +02:00
Julien Nicoulaud
bb0d575942 Merge pull request #85 from jlporter/master
resolve issue #83
2011-12-03 10:38:53 -08:00
Julien Nicoulaud
30c365e030 Add links to Arch Linux and Gentoo packages
(Anyone knowing packages for other systems or wanting to create it,
please get in touch!)
2011-12-03 19:36:25 +01:00
Julien Nicoulaud
2c5c38144d close #84 2011-12-03 19:26:46 +01:00
Jud Porter
d82eee5212 add emulate -L zsh to _zsh_highlight_main_highlighter. resolves issue #83 2011-12-02 16:44:33 -05:00
NAKAMURA Yoshitaka
56b134f5d6 fix "_zsh_highlight_widget_XXX:zle: unknown option: X" error 2011-11-01 20:02:03 +09:00
8 changed files with 68 additions and 24 deletions

View File

@@ -9,6 +9,11 @@ zsh-syntax-highlighting
How to install
--------------
### Using packages
* Arch Linux: [AUR/zsh-syntax-highlighting](https://aur.archlinux.org/packages.php?ID=54171) / [AUR/zsh-syntax-highlighting-git](https://aur.archlinux.org/packages.php?ID=50867)
* Gentoo: [mv overlay](http://gpo.zugaina.org/app-shells/zsh-syntax-highlighting)
### In your ~/.zshrc
* Download the script or clone this repository:
@@ -28,7 +33,7 @@ How to install
* 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/
cd ~/.oh-my-zsh/custom/plugins
git clone git://github.com/zsh-users/zsh-syntax-highlighting.git
* Activate the plugin in `~/.zshrc` (in **last** position):
@@ -43,5 +48,5 @@ How to install
How to tweak
------------
Syntax highlighting is done by pluggable highlighter scripts, see the [highlighters directory](zsh-syntax-highlighting/tree/master/highlighters)
Syntax highlighting is done by pluggable highlighter scripts, see the [highlighters directory](highlighters)
for documentation and configuration settings.

View File

@@ -3,11 +3,11 @@ zsh-syntax-highlighting / highlighters
Syntax highlighting is done by pluggable highlighters:
* [***main***](highlighters/main) - the base highlighter, and the only one active by default.
* [***brackets***](highlighters/brackets) - matches brackets and parenthesis.
* [***pattern***](highlighters/pattern) - matches user-defined patterns.
* [***cursor***](highlighters/cursor) - matches the cursor position.
* [***root***](highlighters/root) - triggered if the current user is root.
* [***main***](main) - the base highlighter, and the only one active by default.
* [***brackets***](brackets) - matches brackets and parenthesis.
* [***pattern***](pattern) - matches user-defined patterns.
* [***cursor***](cursor) - matches the cursor position.
* [***root***](root) - triggered if the current user is root.
How to activate highlighters

View File

@@ -52,18 +52,18 @@ _zsh_highlight_brackets_highlighter()
# Find all brackets and remember which one is matching
for (( pos = 0; $pos < ${#BUFFER}; pos++ )) ; do
local char=$BUFFER[pos+1]
local char="$BUFFER[pos+1]"
case $char in
["([{"])
levelpos[$pos]=$((++level))
lastoflevel[$level]=$pos
_zsh_highlight_brackets_highlighter_brackettype $char
_zsh_highlight_brackets_highlighter_brackettype "$char"
;;
[")]}"])
matching[$lastoflevel[$level]]=$pos
matching[$pos]=$lastoflevel[$level]
levelpos[$pos]=$((level--))
_zsh_highlight_brackets_highlighter_brackettype $char
_zsh_highlight_brackets_highlighter_brackettype "$char"
;;
['"'\'])
# Skip everything inside quotes

View File

@@ -32,6 +32,8 @@ This highlighter defines the following styles:
* `commandseparator` - command separation tokens
* `hashed-command` - hashed commands
* `path` - paths
* `path_prefix` - path prefixes
* `path_approx` - approximated paths
* `globbing` - globbing expressions
* `history-expansion` - history expansion expressions
* `single-hyphen-option` - single hyphen options

View File

@@ -41,6 +41,8 @@
: ${ZSH_HIGHLIGHT_STYLES[commandseparator]:=none}
: ${ZSH_HIGHLIGHT_STYLES[hashed-command]:=fg=green}
: ${ZSH_HIGHLIGHT_STYLES[path]:=underline}
: ${ZSH_HIGHLIGHT_STYLES[path_prefix]:=underline}
: ${ZSH_HIGHLIGHT_STYLES[path_approx]:=fg=yellow,underline}
: ${ZSH_HIGHLIGHT_STYLES[globbing]:=fg=blue}
: ${ZSH_HIGHLIGHT_STYLES[history-expansion]:=fg=blue}
: ${ZSH_HIGHLIGHT_STYLES[single-hyphen-option]:=none}
@@ -61,6 +63,7 @@ _zsh_highlight_main_highlighter_predicate()
# Main syntax highlighting function.
_zsh_highlight_main_highlighter()
{
emulate -L zsh
setopt localoptions extendedglob bareglobqual
local start_pos=0 end_pos highlight_glob=true new_expression=true arg style
typeset -a ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR
@@ -72,7 +75,7 @@ _zsh_highlight_main_highlighter()
'|' '||' ';' '&' '&&'
)
ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS=(
'builtin' 'command' 'exec' 'nocorrect' 'noglob'
'builtin' 'command' 'exec' 'nocorrect' 'noglob' 'sudo'
)
# Tokens that are always immediately followed by a command.
ZSH_HIGHLIGHT_TOKENS_FOLLOWED_BY_COMMANDS=(
@@ -81,6 +84,7 @@ _zsh_highlight_main_highlighter()
for arg in ${(z)BUFFER}; do
local substr_color=0
local style_override=""
[[ $start_pos -eq 0 && $arg = 'noglob' ]] && highlight_glob=false
((start_pos+=${#BUFFER[$start_pos+1,-1]}-${#${BUFFER[$start_pos+1,-1]##[[:space:]]#}}))
((end_pos=$start_pos+${#arg}))
@@ -137,6 +141,8 @@ _zsh_highlight_main_highlighter()
;;
esac
fi
# if a style_override was set (eg in _zsh_highlight_main_highlighter_check_path), use it
[[ -n $style_override ]] && style=$ZSH_HIGHLIGHT_STYLES[$style_override]
[[ $substr_color = 0 ]] && region_highlight+=("$start_pos $end_pos $style")
[[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_FOLLOWED_BY_COMMANDS:#"$arg"} ]] && new_expression=true
start_pos=$end_pos
@@ -157,8 +163,20 @@ _zsh_highlight_main_highlighter_check_path()
local expanded_path; : ${expanded_path:=${(Q)~arg}}
[[ -z $expanded_path ]] && return 1
[[ -e $expanded_path ]] && return 0
# Search the path in CDPATH
for cdpath_dir in $cdpath ; do
[[ -e "$cdpath_dir/$expanded_path" ]] && return 0
done
[[ ! -e ${expanded_path:h} ]] && return 1
[[ ${BUFFER[1]} != "-" && ${#BUFFER} == $end_pos && -n $(print ${expanded_path}*(N)) ]] && return 0
if [[ ${BUFFER[1]} != "-" && ${#BUFFER} == $end_pos ]]; then
local -a tmp
# got a path prefix?
tmp=( ${expanded_path}*(N) )
(( $#tmp > 0 )) && style_override=path_prefix && return 0
# or maybe an approximate path?
tmp=( (#a1)${expanded_path}*(N) )
(( $#tmp > 0 )) && style_override=path_approx && return 0
fi
return 1
}
@@ -166,18 +184,36 @@ _zsh_highlight_main_highlighter_check_path()
_zsh_highlight_main_highlighter_highlight_string()
{
setopt localoptions noksharrays
local i j k style
local i j k style varflag
# Starting quote is at 1, so start parsing at offset 2 in the string.
for (( i = 2 ; i < end_pos - start_pos ; i += 1 )) ; do
(( j = i + start_pos - 1 ))
(( k = j + 1 ))
case "$arg[$i]" in
'$') 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.
'$' ) style=$ZSH_HIGHLIGHT_STYLES[dollar-double-quoted-argument]
(( varflag = 1))
;;
*) continue;;
"\\") style=$ZSH_HIGHLIGHT_STYLES[back-double-quoted-argument]
for (( c = i + 1 ; c < end_pos - start_pos ; c += 1 )); do
[[ "$arg[$c]" != ([0-9,xX,a-f,A-F]) ]] && break
done
AA=$arg[$i+1,$c-1]
# Matching for HEX and OCT values like \0xA6, \xA6 or \012
if [[ "$AA" =~ "^(0*(x|X)[0-9,a-f,A-F]{1,2})" || "$AA" =~ "^(0[0-7]{1,3})" ]];then
(( k += $#MATCH ))
(( i += $#MATCH ))
else
(( k += 1 )) # Color following char too.
(( i += 1 )) # Skip parsing the escaped char.
fi
(( varflag = 0 )) # End of variable
;;
([^a-zA-Z0-9_]))
(( varflag = 0 )) # End of variable
continue
;;
*) [[ $varflag -eq 0 ]] && continue ;;
esac
region_highlight+=("$j $k $style")
done

View File

@@ -42,6 +42,7 @@ _zsh_highlight_pattern_highlighter_predicate()
_zsh_highlight_pattern_highlighter()
{
setopt localoptions extendedglob
local pattern
for pattern in ${(k)ZSH_HIGHLIGHT_PATTERNS}; do
_zsh_highlight_pattern_highlighter_loop "$BUFFER" "$pattern"
done

View File

@@ -41,5 +41,5 @@ _zsh_highlight_root_highlighter_predicate()
# root highlighting function.
_zsh_highlight_root_highlighter()
{
[[ $(command id -u) -eq 0 ]] && region_highlight+=("0 $#BUFFER $ZSH_HIGHLIGHT_STYLES[root]")
if [[ $(command id -u) -eq 0 ]] { region_highlight+=("0 $#BUFFER $ZSH_HIGHLIGHT_STYLES[root]") }
}

View File

@@ -107,7 +107,7 @@ typeset -gA ZSH_HIGHLIGHT_STYLES
# Returns 0 if the buffer has changed since _zsh_highlight was last called.
_zsh_highlight_buffer_modified()
{
[[ ${_ZSH_HIGHLIGHT_PRIOR_BUFFER:-} != $BUFFER ]]
[[ "${_ZSH_HIGHLIGHT_PRIOR_BUFFER:-}" != "$BUFFER" ]]
}
# Whether the cursor has moved or not.
@@ -142,16 +142,16 @@ _zsh_highlight_bind_widgets()
# User defined widget: override and rebind old one with prefix "orig-".
user:*) eval "zle -N orig-$cur_widget ${widgets[$cur_widget]#*:}; \
_zsh_highlight_widget_$cur_widget() { builtin zle orig-$cur_widget \"\$@\" && _zsh_highlight }; \
_zsh_highlight_widget_$cur_widget() { builtin zle orig-$cur_widget -- \"\$@\" && _zsh_highlight }; \
zle -N $cur_widget _zsh_highlight_widget_$cur_widget";;
# Completion widget: override and rebind old one with prefix "orig-".
completion:*) eval "zle -C orig-$cur_widget ${${widgets[$cur_widget]#*:}/:/ }; \
_zsh_highlight_widget_$cur_widget() { builtin zle orig-$cur_widget \"\$@\" && _zsh_highlight }; \
_zsh_highlight_widget_$cur_widget() { builtin zle orig-$cur_widget -- \"\$@\" && _zsh_highlight }; \
zle -N $cur_widget _zsh_highlight_widget_$cur_widget";;
# Builtin widget: override and make it call the builtin ".widget".
builtin) eval "_zsh_highlight_widget_$cur_widget() { builtin zle .$cur_widget \"\$@\" && _zsh_highlight }; \
builtin) eval "_zsh_highlight_widget_$cur_widget() { builtin zle .$cur_widget -- \"\$@\" && _zsh_highlight }; \
zle -N $cur_widget _zsh_highlight_widget_$cur_widget";;
# Default: unhandled case.