Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1089e3a408 |
@@ -1,3 +1,5 @@
|
||||
**This branch will be rebased from time to time.**
|
||||
|
||||
zsh-syntax-highlighting [![Build Status][build-status-image]][build-status-travis]
|
||||
=======================
|
||||
|
||||
|
||||
@@ -44,6 +44,18 @@ page][zshzle-Character-Highlighting].
|
||||
|
||||
[zshzle-Character-Highlighting]: http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting
|
||||
|
||||
Styles may be set directly or by themes. If no theme is specified in
|
||||
`ZSH_HIGHLIGHT_THEME` the `default` theme will be loaded. Additional themes
|
||||
may be layered on top (overriding previous theme's settings) by calling
|
||||
`_zsh_highlight_load_theme`. `_zsh_highlight_load_theme` takes either an
|
||||
absolute path to a theme file to load or a theme name. For a theme name the
|
||||
base theme from the themes directory is loaded and then the extensions of the
|
||||
theme that any active highlighter has are loaded. Names must not contain a `/`.
|
||||
|
||||
The `default` theme is a colorful theme that preserves the defaults the
|
||||
highlighters originally had. The `error-only` theme is also available for
|
||||
highlighting only syntax errors.
|
||||
|
||||
Some highlighters support additional configuration parameters; see each
|
||||
highlighter's documentation for details and examples.
|
||||
|
||||
@@ -70,13 +82,8 @@ To create your own `acme` highlighter:
|
||||
* Implement the `_zsh_highlight_highlighter_acme_paint` function.
|
||||
This function does the actual syntax highlighting, by calling
|
||||
`_zsh_highlight_add_highlight` with the start and end of the region to
|
||||
be highlighted and the `ZSH_HIGHLIGHT_STYLES` key to use. Define the default
|
||||
style for that key in the highlighter script outside of any function with
|
||||
`: ${ZSH_HIGHLIGHT_STYLES[key]:=value}`, being sure to prefix
|
||||
the key with your highlighter name and a colon. For example:
|
||||
|
||||
```zsh
|
||||
: ${ZSH_HIGHLIGHT_STYLES[acme:aurora]:=fg=green}
|
||||
be highlighted and the `ZSH_HIGHLIGHT_STYLES` key to use. The key should
|
||||
be prefixed with your highlighter name and a colon
|
||||
|
||||
_zsh_highlight_highlighter_acme_paint() {
|
||||
# Colorize the whole buffer with the 'aurora' style
|
||||
@@ -106,6 +113,15 @@ To create your own `acme` highlighter:
|
||||
These names are still supported for backwards compatibility;
|
||||
however, support for them will be removed in a a future major or minor release (v0.x.0 or v1.0.0).
|
||||
|
||||
* Optionally extended the built-in themes in
|
||||
`highlighters/${myhighlighter}/themes/${themename}`.
|
||||
|
||||
Define the theme's style for that key with `ZSH_HIGHLIGHT_STYLES[key]=value`,
|
||||
being sure to prefix the key with your highlighter name and a colon. For
|
||||
example:
|
||||
|
||||
ZSH_HIGHLIGHT_STYLES[myhighlighter:aurora]=fg=green
|
||||
|
||||
* Activate your highlighter in `~/.zshrc`:
|
||||
|
||||
```zsh
|
||||
|
||||
@@ -85,11 +85,11 @@ manual page][zshzle-Character-Highlighting].
|
||||
|
||||
#### Parameters
|
||||
|
||||
To avoid partial path lookups on a path, add the path to the `ZSH_HIGHLIGHT_DIRS_BLACKLIST` array.
|
||||
To avoid partial path lookups on a path, add the path to the `X_ZSH_HIGHLIGHT_DIRS_BLACKLIST` array.
|
||||
This interface is still experimental.
|
||||
|
||||
```zsh
|
||||
ZSH_HIGHLIGHT_DIRS_BLACKLIST+=(/mnt/slow_share)
|
||||
X_ZSH_HIGHLIGHT_DIRS_BLACKLIST+=(/mnt/slow_share)
|
||||
```
|
||||
|
||||
### Useless trivia
|
||||
|
||||
@@ -28,15 +28,6 @@
|
||||
# -------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
# Define default styles.
|
||||
: ${ZSH_HIGHLIGHT_STYLES[bracket-error]:=fg=red,bold}
|
||||
: ${ZSH_HIGHLIGHT_STYLES[bracket-level-1]:=fg=blue,bold}
|
||||
: ${ZSH_HIGHLIGHT_STYLES[bracket-level-2]:=fg=green,bold}
|
||||
: ${ZSH_HIGHLIGHT_STYLES[bracket-level-3]:=fg=magenta,bold}
|
||||
: ${ZSH_HIGHLIGHT_STYLES[bracket-level-4]:=fg=yellow,bold}
|
||||
: ${ZSH_HIGHLIGHT_STYLES[bracket-level-5]:=fg=cyan,bold}
|
||||
: ${ZSH_HIGHLIGHT_STYLES[cursor-matchingbracket]:=standout}
|
||||
|
||||
# Whether the brackets highlighter should be called or not.
|
||||
_zsh_highlight_highlighter_brackets_predicate()
|
||||
{
|
||||
|
||||
@@ -28,9 +28,6 @@
|
||||
# -------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
# Define default styles.
|
||||
: ${ZSH_HIGHLIGHT_STYLES[cursor]:=standout}
|
||||
|
||||
# Whether the cursor highlighter should be called or not.
|
||||
_zsh_highlight_highlighter_cursor_predicate()
|
||||
{
|
||||
|
||||
@@ -28,9 +28,6 @@
|
||||
# -------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
# Define default styles.
|
||||
: ${ZSH_HIGHLIGHT_STYLES[line]:=}
|
||||
|
||||
# Whether the root highlighter should be called or not.
|
||||
_zsh_highlight_highlighter_line_predicate()
|
||||
{
|
||||
|
||||
@@ -28,39 +28,6 @@
|
||||
# -------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
# Define default styles.
|
||||
: ${ZSH_HIGHLIGHT_STYLES[default]:=none}
|
||||
: ${ZSH_HIGHLIGHT_STYLES[unknown-token]:=fg=red,bold}
|
||||
: ${ZSH_HIGHLIGHT_STYLES[reserved-word]:=fg=yellow}
|
||||
: ${ZSH_HIGHLIGHT_STYLES[suffix-alias]:=fg=green,underline}
|
||||
: ${ZSH_HIGHLIGHT_STYLES[precommand]:=fg=green,underline}
|
||||
: ${ZSH_HIGHLIGHT_STYLES[commandseparator]:=none}
|
||||
: ${ZSH_HIGHLIGHT_STYLES[path]:=underline}
|
||||
: ${ZSH_HIGHLIGHT_STYLES[path_pathseparator]:=}
|
||||
: ${ZSH_HIGHLIGHT_STYLES[path_prefix_pathseparator]:=}
|
||||
: ${ZSH_HIGHLIGHT_STYLES[globbing]:=fg=blue}
|
||||
: ${ZSH_HIGHLIGHT_STYLES[history-expansion]:=fg=blue}
|
||||
: ${ZSH_HIGHLIGHT_STYLES[command-substitution]:=none}
|
||||
: ${ZSH_HIGHLIGHT_STYLES[command-substitution-delimiter]:=fg=magenta}
|
||||
: ${ZSH_HIGHLIGHT_STYLES[process-substitution]:=none}
|
||||
: ${ZSH_HIGHLIGHT_STYLES[process-substitution-delimiter]:=fg=magenta}
|
||||
: ${ZSH_HIGHLIGHT_STYLES[single-hyphen-option]:=none}
|
||||
: ${ZSH_HIGHLIGHT_STYLES[double-hyphen-option]:=none}
|
||||
: ${ZSH_HIGHLIGHT_STYLES[back-quoted-argument]:=none}
|
||||
: ${ZSH_HIGHLIGHT_STYLES[back-quoted-argument-delimiter]:=fg=magenta}
|
||||
: ${ZSH_HIGHLIGHT_STYLES[single-quoted-argument]:=fg=yellow}
|
||||
: ${ZSH_HIGHLIGHT_STYLES[double-quoted-argument]:=fg=yellow}
|
||||
: ${ZSH_HIGHLIGHT_STYLES[dollar-quoted-argument]:=fg=yellow}
|
||||
: ${ZSH_HIGHLIGHT_STYLES[rc-quote]:=fg=cyan}
|
||||
: ${ZSH_HIGHLIGHT_STYLES[dollar-double-quoted-argument]:=fg=cyan}
|
||||
: ${ZSH_HIGHLIGHT_STYLES[back-double-quoted-argument]:=fg=cyan}
|
||||
: ${ZSH_HIGHLIGHT_STYLES[back-dollar-quoted-argument]:=fg=cyan}
|
||||
: ${ZSH_HIGHLIGHT_STYLES[assign]:=none}
|
||||
: ${ZSH_HIGHLIGHT_STYLES[redirection]:=none}
|
||||
: ${ZSH_HIGHLIGHT_STYLES[comment]:=fg=black,bold}
|
||||
: ${ZSH_HIGHLIGHT_STYLES[named-fd]:=none}
|
||||
: ${ZSH_HIGHLIGHT_STYLES[arg0]:=fg=green}
|
||||
|
||||
# Whether the highlighter should be called or not.
|
||||
_zsh_highlight_highlighter_main_predicate()
|
||||
{
|
||||
@@ -311,17 +278,12 @@ _zsh_highlight_highlighter_main_paint()
|
||||
'exec' a:cl
|
||||
'nocorrect' ''
|
||||
'noglob' ''
|
||||
'time' ''
|
||||
|
||||
'doas' aCu:Lns # as of OpenBSD's doas(1) dated September 4, 2016
|
||||
'nice' n: # as of current POSIX spec
|
||||
'pkexec' '' # doesn't take short options; immune to #121 because it's usually not passed --option flags
|
||||
'sudo' Cgprtu:AEHKPSVbhiklnsv # as of sudo 1.8.21p2
|
||||
'stdbuf' ioe:
|
||||
'eatmydata' ''
|
||||
'catchsegv' ''
|
||||
'nohup' ''
|
||||
'setsid' :wc
|
||||
)
|
||||
|
||||
if [[ $zsyh_user_options[ignorebraces] == on || ${zsyh_user_options[ignoreclosebraces]:-off} == on ]]; then
|
||||
@@ -360,12 +322,6 @@ _zsh_highlight_highlighter_main_paint()
|
||||
'!' # reserved word; unrelated to $histchars[1]
|
||||
)
|
||||
|
||||
if (( $+X_ZSH_HIGHLIGHT_DIRS_BLACKLIST )); then
|
||||
print >&2 'zsh-syntax-highlighting: X_ZSH_HIGHLIGHT_DIRS_BLACKLIST is deprecated. Please use ZSH_HIGHLIGHT_DIRS_BLACKLIST.'
|
||||
ZSH_HIGHLIGHT_DIRS_BLACKLIST=($X_ZSH_HIGHLIGHT_DIRS_BLACKLIST)
|
||||
unset X_ZSH_HIGHLIGHT_DIRS_BLACKLIST
|
||||
fi
|
||||
|
||||
_zsh_highlight_main_highlighter_highlight_list -$#PREBUFFER '' 1 "$PREBUFFER$BUFFER"
|
||||
|
||||
# end is a reserved word
|
||||
@@ -393,7 +349,9 @@ _zsh_highlight_main_highlighter_highlight_list()
|
||||
# alias_style is the style to apply to an alias once in_alias=0
|
||||
# Usually 'alias' but set to 'unknown-token' if any word expanded from
|
||||
# the alias would be highlighted as unknown-token
|
||||
local alias_style arg buf=$4 highlight_glob=true style
|
||||
# last_alias is the last alias arg (lhs) expanded (if in an alias).
|
||||
# This allows for expanding alias ls='ls -l' while avoiding loops.
|
||||
local alias_style arg buf=$4 highlight_glob=true last_alias style
|
||||
local in_array_assignment=false # true between 'a=(' and the matching ')'
|
||||
# in_alias is equal to the number of shifts needed until arg=args[1] pops an
|
||||
# arg from BUFFER and not added by an alias.
|
||||
@@ -471,7 +429,7 @@ _zsh_highlight_main_highlighter_highlight_list()
|
||||
if (( in_alias )); then
|
||||
(( in_alias-- ))
|
||||
if (( in_alias == 0 )); then
|
||||
seen_alias=()
|
||||
last_alias= seen_alias=()
|
||||
# start_pos and end_pos are of the alias (previous $arg) here
|
||||
_zsh_highlight_main_add_region_highlight $start_pos $end_pos $alias_style
|
||||
fi
|
||||
@@ -545,17 +503,18 @@ _zsh_highlight_main_highlighter_highlight_list()
|
||||
|
||||
if [[ $this_word == *:start:* ]] && ! (( in_redirection )); then
|
||||
# Expand aliases.
|
||||
# An alias is ineligible for expansion while it's being expanded (see #652/#653).
|
||||
_zsh_highlight_main__type "$arg" "$(( ! ${+seen_alias[$arg]} ))"
|
||||
_zsh_highlight_main__type "$arg"
|
||||
local res="$REPLY"
|
||||
if [[ $res == "alias" ]]; then
|
||||
# Mark insane aliases as unknown-token (cf. #263).
|
||||
if [[ $arg == ?*=* ]]; then
|
||||
if [[ $res == "alias" ]] && [[ $last_alias != $arg ]]; then
|
||||
# Avoid looping forever on alias a=b b=c c=b, but allow alias foo='foo bar'
|
||||
# Also mark insane aliases as unknown-token (cf. #263).
|
||||
if (( $+seen_alias[$arg] )) || [[ $arg == ?*=* ]]; then
|
||||
(( in_alias == 0 )) && in_alias=1
|
||||
_zsh_highlight_main_add_region_highlight $start_pos $end_pos unknown-token
|
||||
continue
|
||||
fi
|
||||
seen_alias[$arg]=1
|
||||
last_alias=$arg
|
||||
_zsh_highlight_main__resolve_alias $arg
|
||||
local -a alias_args
|
||||
# Elision is desired in case alias x=''
|
||||
@@ -809,7 +768,7 @@ _zsh_highlight_main_highlighter_highlight_list()
|
||||
# Discard :start_of_pipeline:, if present, as '!' is not valid
|
||||
# after assignments.
|
||||
next_word+=':start:'
|
||||
if (( i <= $#arg )); then
|
||||
if (( start_pos + i <= end_pos )); then
|
||||
() {
|
||||
local highlight_glob=false
|
||||
[[ $zsyh_user_options[globassign] == on ]] && highlight_glob=true
|
||||
@@ -974,7 +933,7 @@ _zsh_highlight_main_highlighter_check_path()
|
||||
tmp_path=$tmp_path:a
|
||||
|
||||
while [[ $tmp_path != / ]]; do
|
||||
[[ -n ${(M)ZSH_HIGHLIGHT_DIRS_BLACKLIST:#$tmp_path} ]] && return 1
|
||||
[[ -n ${(M)X_ZSH_HIGHLIGHT_DIRS_BLACKLIST:#$tmp_path} ]] && return 1
|
||||
tmp_path=$tmp_path:h
|
||||
done
|
||||
|
||||
@@ -1032,7 +991,7 @@ _zsh_highlight_main_highlighter_highlight_argument()
|
||||
'=')
|
||||
if [[ $arg[i+1] == $'\x28' ]]; then
|
||||
(( i += 2 ))
|
||||
_zsh_highlight_main_highlighter_highlight_list $(( start_pos + i - 1 )) S $has_end $arg[i,-1]
|
||||
_zsh_highlight_main_highlighter_highlight_list $(( start_pos + i - 1 )) S $has_end $arg[i,end_pos]
|
||||
ret=$?
|
||||
(( i += REPLY ))
|
||||
highlights+=(
|
||||
@@ -1046,7 +1005,7 @@ _zsh_highlight_main_highlighter_highlight_argument()
|
||||
fi
|
||||
esac
|
||||
|
||||
for (( ; i <= $#arg ; i += 1 )); do
|
||||
for (( ; i <= end_pos - start_pos ; i += 1 )); do
|
||||
case "$arg[$i]" in
|
||||
"\\") (( i += 1 )); continue;;
|
||||
"'")
|
||||
@@ -1076,7 +1035,7 @@ _zsh_highlight_main_highlighter_highlight_argument()
|
||||
elif [[ $arg[i+1] == $'\x28' ]]; then
|
||||
start=$i
|
||||
(( i += 2 ))
|
||||
_zsh_highlight_main_highlighter_highlight_list $(( start_pos + i - 1 )) S $has_end $arg[i,-1]
|
||||
_zsh_highlight_main_highlighter_highlight_list $(( start_pos + i - 1 )) S $has_end $arg[i,end_pos]
|
||||
ret=$?
|
||||
(( i += REPLY ))
|
||||
highlights+=(
|
||||
@@ -1099,7 +1058,7 @@ _zsh_highlight_main_highlighter_highlight_argument()
|
||||
if [[ $arg[i+1] == $'\x28' ]]; then # \x28 = open paren
|
||||
start=$i
|
||||
(( i += 2 ))
|
||||
_zsh_highlight_main_highlighter_highlight_list $(( start_pos + i - 1 )) S $has_end $arg[i,-1]
|
||||
_zsh_highlight_main_highlighter_highlight_list $(( start_pos + i - 1 )) S $has_end $arg[i,end_pos]
|
||||
ret=$?
|
||||
(( i += REPLY ))
|
||||
highlights+=(
|
||||
@@ -1125,7 +1084,7 @@ _zsh_highlight_main_highlighter_highlight_argument()
|
||||
esac
|
||||
done
|
||||
|
||||
if (( path_eligible )) && _zsh_highlight_main_highlighter_check_path $arg[$1,-1]; then
|
||||
if (( path_eligible )) && _zsh_highlight_main_highlighter_check_path $arg[$1,end_pos]; then
|
||||
base_style=$REPLY
|
||||
_zsh_highlight_main_highlighter_highlight_path_separators $base_style
|
||||
highlights+=($reply)
|
||||
@@ -1177,7 +1136,7 @@ _zsh_highlight_main_highlighter_highlight_double_quote()
|
||||
local i j k ret style
|
||||
reply=()
|
||||
|
||||
for (( i = $1 + 1 ; i <= $#arg ; i += 1 )) ; do
|
||||
for (( i = $1 + 1 ; i <= end_pos - start_pos ; i += 1 )) ; do
|
||||
(( j = i + start_pos - 1 ))
|
||||
(( k = j + 1 ))
|
||||
case "$arg[$i]" in
|
||||
@@ -1208,7 +1167,7 @@ _zsh_highlight_main_highlighter_highlight_double_quote()
|
||||
breaks+=( $last_break $(( start_pos + i - 1 )) )
|
||||
(( i += 2 ))
|
||||
saved_reply=($reply)
|
||||
_zsh_highlight_main_highlighter_highlight_list $(( start_pos + i - 1 )) S $has_end $arg[i,-1]
|
||||
_zsh_highlight_main_highlighter_highlight_list $(( start_pos + i - 1 )) S $has_end $arg[i,end_pos]
|
||||
ret=$?
|
||||
(( i += REPLY ))
|
||||
last_break=$(( start_pos + i ))
|
||||
@@ -1274,13 +1233,13 @@ _zsh_highlight_main_highlighter_highlight_dollar_quote()
|
||||
integer c
|
||||
reply=()
|
||||
|
||||
for (( i = $1 + 2 ; i <= $#arg ; i += 1 )) ; do
|
||||
for (( i = $1 + 2 ; i <= end_pos - start_pos ; i += 1 )) ; do
|
||||
(( j = i + start_pos - 1 ))
|
||||
(( k = j + 1 ))
|
||||
case "$arg[$i]" in
|
||||
"'") break;;
|
||||
"\\") style=back-dollar-quoted-argument
|
||||
for (( c = i + 1 ; c <= $#arg ; c += 1 )); do
|
||||
for (( c = i + 1 ; c <= end_pos - start_pos ; c += 1 )); do
|
||||
[[ "$arg[$c]" != ([0-9xXuUa-fA-F]) ]] && break
|
||||
done
|
||||
AA=$arg[$i+1,$c-1]
|
||||
@@ -1335,7 +1294,7 @@ _zsh_highlight_main_highlighter_highlight_backtick()
|
||||
last=$(( arg1 + 1 ))
|
||||
# Remove one layer of backslashes and find the end
|
||||
while i=$arg[(ib:i+1:)[\\\\\`]]; do # find the next \ or `
|
||||
if (( i > $#arg )); then
|
||||
if (( i > end_pos - start_pos )); then
|
||||
buf=$buf$arg[last,i]
|
||||
offsets[i-arg1-offset]='' # So we never index past the end
|
||||
(( i-- ))
|
||||
@@ -1419,4 +1378,4 @@ else
|
||||
# Make sure the cache is unset
|
||||
unset _zsh_highlight_main__command_type_cache
|
||||
fi
|
||||
typeset -ga ZSH_HIGHLIGHT_DIRS_BLACKLIST
|
||||
typeset -ga X_ZSH_HIGHLIGHT_DIRS_BLACKLIST
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
# -------------------------------------------------------------------------------------------------
|
||||
# Copyright (c) 2019 zsh-syntax-highlighting contributors
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without modification, are permitted
|
||||
# provided that the following conditions are met:
|
||||
#
|
||||
# * Redistributions of source code must retain the above copyright notice, this list of conditions
|
||||
# and the following disclaimer.
|
||||
# * Redistributions in binary form must reproduce the above copyright notice, this list of
|
||||
# conditions and the following disclaimer in the documentation and/or other materials provided
|
||||
# with the distribution.
|
||||
# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors
|
||||
# may be used to endorse or promote products derived from this software without specific prior
|
||||
# written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
|
||||
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
|
||||
# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
# -------------------------------------------------------------------------------------------------
|
||||
# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*-
|
||||
# vim: ft=zsh sw=2 ts=2 et
|
||||
# -------------------------------------------------------------------------------------------------
|
||||
|
||||
# Alias must be at least 4 characters to test the regression
|
||||
# cf. 139ea2b189819c43cc251825981c116959b15cc3
|
||||
alias foobar='echo "$(echo foobar)"'
|
||||
BUFFER='foobar'
|
||||
|
||||
expected_region_highlight=(
|
||||
"1 6 alias" # foobar
|
||||
)
|
||||
@@ -1,36 +0,0 @@
|
||||
# -------------------------------------------------------------------------------------------------
|
||||
# Copyright (c) 2019 zsh-syntax-highlighting contributors
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without modification, are permitted
|
||||
# provided that the following conditions are met:
|
||||
#
|
||||
# * Redistributions of source code must retain the above copyright notice, this list of conditions
|
||||
# and the following disclaimer.
|
||||
# * Redistributions in binary form must reproduce the above copyright notice, this list of
|
||||
# conditions and the following disclaimer in the documentation and/or other materials provided
|
||||
# with the distribution.
|
||||
# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors
|
||||
# may be used to endorse or promote products derived from this software without specific prior
|
||||
# written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
|
||||
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
|
||||
# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
# -------------------------------------------------------------------------------------------------
|
||||
# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*-
|
||||
# vim: ft=zsh sw=2 ts=2 et
|
||||
# -------------------------------------------------------------------------------------------------
|
||||
|
||||
alias ls='command ls'
|
||||
|
||||
BUFFER='ls'
|
||||
|
||||
expected_region_highlight=(
|
||||
"1 2 alias" # ls
|
||||
)
|
||||
@@ -1,36 +0,0 @@
|
||||
# -------------------------------------------------------------------------------------------------
|
||||
# Copyright (c) 2019 zsh-syntax-highlighting contributors
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without modification, are permitted
|
||||
# provided that the following conditions are met:
|
||||
#
|
||||
# * Redistributions of source code must retain the above copyright notice, this list of conditions
|
||||
# and the following disclaimer.
|
||||
# * Redistributions in binary form must reproduce the above copyright notice, this list of
|
||||
# conditions and the following disclaimer in the documentation and/or other materials provided
|
||||
# with the distribution.
|
||||
# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors
|
||||
# may be used to endorse or promote products derived from this software without specific prior
|
||||
# written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
|
||||
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
|
||||
# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
# -------------------------------------------------------------------------------------------------
|
||||
# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*-
|
||||
# vim: ft=zsh sw=2 ts=2 et
|
||||
# -------------------------------------------------------------------------------------------------
|
||||
|
||||
alias ls=tmp tmp='command ls'
|
||||
|
||||
BUFFER='ls'
|
||||
|
||||
expected_region_highlight=(
|
||||
"1 2 alias" # ls
|
||||
)
|
||||
@@ -30,7 +30,7 @@
|
||||
mkdir foo
|
||||
touch foo/bar
|
||||
BUFFER=": foo/bar $PWD/foo foo/b"
|
||||
ZSH_HIGHLIGHT_DIRS_BLACKLIST=($PWD/foo $PWD/bar)
|
||||
X_ZSH_HIGHLIGHT_DIRS_BLACKLIST=($PWD/foo $PWD/bar)
|
||||
|
||||
expected_region_highlight=(
|
||||
'1 1 builtin' # :
|
||||
|
||||
@@ -28,12 +28,10 @@
|
||||
# vim: ft=zsh sw=2 ts=2 et
|
||||
# -------------------------------------------------------------------------------------------------
|
||||
|
||||
# Newline after semicolon isn't unknown-token
|
||||
BUFFER=$':;\n:'
|
||||
BUFFER=$':;\n'
|
||||
|
||||
expected_region_highlight=(
|
||||
'1 1 builtin' # :
|
||||
'2 2 commandseparator' # ;
|
||||
'3 3 commandseparator "issue #616"' # \n
|
||||
'4 4 builtin' # :
|
||||
'3 3 issue-623 "issue #616"' # \n
|
||||
)
|
||||
|
||||
@@ -28,9 +28,6 @@
|
||||
# -------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
# Define default styles.
|
||||
: ${ZSH_HIGHLIGHT_STYLES[root]:=standout}
|
||||
|
||||
# Whether the root highlighter should be called or not.
|
||||
_zsh_highlight_highlighter_root_predicate()
|
||||
{
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
`tig --abbrev=12 --abbrev-commit 0.4.1..upstream/master`
|
||||
- Remove `-dev` suffix from `./.version`;
|
||||
Commit that using `git commit -m "Tag version $(<.version)." .version`;
|
||||
Tag it using `git tag -s -m "Tag version $(<.version)"`;
|
||||
Tag it using `git tag -m "Tag version $(<.version)"`;
|
||||
Increment `./.version` and restore the `-dev` suffix;
|
||||
Commit that using `git commit -C b5c30ae52638e81a38fe5329081c5613d7bd6ca5 .version`.
|
||||
- Push with `git push && git push --tags`
|
||||
|
||||
50
themes/default
Normal file
50
themes/default
Normal file
@@ -0,0 +1,50 @@
|
||||
# brackets
|
||||
ZSH_HIGHLIGHT_STYLES[bracket-error]=fg=red,bold
|
||||
ZSH_HIGHLIGHT_STYLES[bracket-level-1]=fg=blue,bold
|
||||
ZSH_HIGHLIGHT_STYLES[bracket-level-2]=fg=green,bold
|
||||
ZSH_HIGHLIGHT_STYLES[bracket-level-3]=fg=magenta,bold
|
||||
ZSH_HIGHLIGHT_STYLES[bracket-level-4]=fg=yellow,bold
|
||||
ZSH_HIGHLIGHT_STYLES[bracket-level-5]=fg=cyan,bold
|
||||
ZSH_HIGHLIGHT_STYLES[cursor-matchingbracket]=standout
|
||||
|
||||
# cursor
|
||||
ZSH_HIGHLIGHT_STYLES[cursor]=standout
|
||||
|
||||
# line
|
||||
ZSH_HIGHLIGHT_STYLES[line]=
|
||||
|
||||
# main
|
||||
ZSH_HIGHLIGHT_STYLES[default]=none
|
||||
ZSH_HIGHLIGHT_STYLES[unknown-token]=fg=red,bold
|
||||
ZSH_HIGHLIGHT_STYLES[reserved-word]=fg=yellow
|
||||
ZSH_HIGHLIGHT_STYLES[suffix-alias]=fg=green,underline
|
||||
ZSH_HIGHLIGHT_STYLES[precommand]=fg=green,underline
|
||||
ZSH_HIGHLIGHT_STYLES[commandseparator]=none
|
||||
ZSH_HIGHLIGHT_STYLES[path]=underline
|
||||
ZSH_HIGHLIGHT_STYLES[path_pathseparator]=
|
||||
ZSH_HIGHLIGHT_STYLES[path_prefix_pathseparator]=
|
||||
ZSH_HIGHLIGHT_STYLES[globbing]=fg=blue
|
||||
ZSH_HIGHLIGHT_STYLES[history-expansion]=fg=blue
|
||||
ZSH_HIGHLIGHT_STYLES[command-substitution]=none
|
||||
ZSH_HIGHLIGHT_STYLES[command-substitution-delimiter]=fg=magenta
|
||||
ZSH_HIGHLIGHT_STYLES[process-substitution]=none
|
||||
ZSH_HIGHLIGHT_STYLES[process-substitution-delimiter]=fg=magenta
|
||||
ZSH_HIGHLIGHT_STYLES[single-hyphen-option]=none
|
||||
ZSH_HIGHLIGHT_STYLES[double-hyphen-option]=none
|
||||
ZSH_HIGHLIGHT_STYLES[back-quoted-argument]=none
|
||||
ZSH_HIGHLIGHT_STYLES[back-quoted-argument-delimiter]=fg=magenta
|
||||
ZSH_HIGHLIGHT_STYLES[single-quoted-argument]=fg=yellow
|
||||
ZSH_HIGHLIGHT_STYLES[double-quoted-argument]=fg=yellow
|
||||
ZSH_HIGHLIGHT_STYLES[dollar-quoted-argument]=fg=yellow
|
||||
ZSH_HIGHLIGHT_STYLES[rc-quote]=fg=cyan
|
||||
ZSH_HIGHLIGHT_STYLES[dollar-double-quoted-argument]=fg=cyan
|
||||
ZSH_HIGHLIGHT_STYLES[back-double-quoted-argument]=fg=cyan
|
||||
ZSH_HIGHLIGHT_STYLES[back-dollar-quoted-argument]=fg=cyan
|
||||
ZSH_HIGHLIGHT_STYLES[assign]=none
|
||||
ZSH_HIGHLIGHT_STYLES[redirection]=none
|
||||
ZSH_HIGHLIGHT_STYLES[comment]=fg=black,bold
|
||||
ZSH_HIGHLIGHT_STYLES[named-fd]=none
|
||||
ZSH_HIGHLIGHT_STYLES[arg0]=fg=green
|
||||
|
||||
# root
|
||||
ZSH_HIGHLIGHT_STYLES[root]=standout
|
||||
2
themes/error-only
Normal file
2
themes/error-only
Normal file
@@ -0,0 +1,2 @@
|
||||
ZSH_HIGHLIGHT_STYLES[bracket-error]=fg=red,bold
|
||||
ZSH_HIGHLIGHT_STYLES[unknown-token]=fg=red,bold
|
||||
@@ -157,25 +157,24 @@ _zsh_highlight()
|
||||
# Re-apply zle_highlight settings
|
||||
|
||||
# region
|
||||
if (( REGION_ACTIVE == 1 )); then
|
||||
_zsh_highlight_apply_zle_highlight region standout "$MARK" "$CURSOR"
|
||||
elif (( REGION_ACTIVE == 2 )); then
|
||||
() {
|
||||
(( REGION_ACTIVE )) || return
|
||||
local needle=$'\n'
|
||||
integer min max
|
||||
if (( MARK > CURSOR )) ; then
|
||||
min=$CURSOR max=$MARK
|
||||
else
|
||||
min=$MARK max=$CURSOR
|
||||
fi
|
||||
if (( REGION_ACTIVE == 1 )); then
|
||||
[[ $KEYMAP = vicmd ]] && (( max++ ))
|
||||
elif (( REGION_ACTIVE == 2 )); then
|
||||
local needle=$'\n'
|
||||
# CURSOR and MARK are 0 indexed between letters like region_highlight
|
||||
# Do not include the newline in the highlight
|
||||
(( min = ${BUFFER[(Ib:min:)$needle]} ))
|
||||
(( max = ${BUFFER[(ib:max:)$needle]} - 1 ))
|
||||
fi
|
||||
_zsh_highlight_apply_zle_highlight region standout "$min" "$max"
|
||||
}
|
||||
fi
|
||||
|
||||
# yank / paste (zsh-5.1.1 and newer)
|
||||
(( $+YANK_ACTIVE )) && (( YANK_ACTIVE )) && _zsh_highlight_apply_zle_highlight paste standout "$YANK_START" "$YANK_END"
|
||||
@@ -400,6 +399,24 @@ _zsh_highlight_load_highlighters()
|
||||
}
|
||||
|
||||
|
||||
# Load theme
|
||||
# $1 should be a theme defined in themes/ or an absolute path
|
||||
_zsh_highlight_load_theme()
|
||||
{
|
||||
local theme=$1
|
||||
shift 1
|
||||
if [[ ${theme[1]} == / ]]; then
|
||||
source $theme
|
||||
elif [[ $theme == */* ]]; then
|
||||
print -r -- >&2 "zsh-syntax-highlighting: failed on invalid theme name: ${(qq)theme}"
|
||||
return 1
|
||||
else
|
||||
for theme in ${ZSH_HIGHLIGHT_HIGHLIGHTERS_DIR:h}/themes/$theme(N) $ZSH_HIGHLIGHT_HIGHLIGHTERS_DIR/$^ZSH_HIGHLIGHT_HIGHLIGHTERS/$theme(N); do
|
||||
source $theme
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
# -------------------------------------------------------------------------------------------------
|
||||
# Setup
|
||||
# -------------------------------------------------------------------------------------------------
|
||||
@@ -411,7 +428,7 @@ _zsh_highlight_bind_widgets || {
|
||||
}
|
||||
|
||||
# Resolve highlighters directory location.
|
||||
_zsh_highlight_load_highlighters "${ZSH_HIGHLIGHT_HIGHLIGHTERS_DIR:-${${0:A}:h}/highlighters}" || {
|
||||
_zsh_highlight_load_highlighters "${ZSH_HIGHLIGHT_HIGHLIGHTERS_DIR:=${${0:A}:h}/highlighters}" || {
|
||||
print -r -- >&2 'zsh-syntax-highlighting: failed loading highlighters, exiting.'
|
||||
return 1
|
||||
}
|
||||
@@ -433,11 +450,8 @@ zmodload zsh/parameter 2>/dev/null || true
|
||||
# Initialize the array of active highlighters if needed.
|
||||
[[ $#ZSH_HIGHLIGHT_HIGHLIGHTERS -eq 0 ]] && ZSH_HIGHLIGHT_HIGHLIGHTERS=(main)
|
||||
|
||||
if (( $+X_ZSH_HIGHLIGHT_DIRS_BLACKLIST )); then
|
||||
print >&2 'zsh-syntax-highlighting: X_ZSH_HIGHLIGHT_DIRS_BLACKLIST is deprecated. Please use ZSH_HIGHLIGHT_DIRS_BLACKLIST.'
|
||||
ZSH_HIGHLIGHT_DIRS_BLACKLIST=($X_ZSH_HIGHLIGHT_DIRS_BLACKLIST)
|
||||
unset X_ZSH_HIGHLIGHT_DIRS_BLACKLIST
|
||||
fi
|
||||
# Load the theme.
|
||||
_zsh_highlight_load_theme "${ZSH_HIGHLIGHT_THEME-default}"
|
||||
|
||||
# Restore the aliases we unned
|
||||
eval "$zsh_highlight__aliases"
|
||||
|
||||
Reference in New Issue
Block a user