parent
cbbfae1176
commit
6ba51f632e
@ -0,0 +1,3 @@
|
|||||||
|
color
|
||||||
|
zsh.conf
|
||||||
|
|
@ -0,0 +1,26 @@
|
|||||||
|
if [ $BSD_MODE ]
|
||||||
|
then
|
||||||
|
alias ls='ls -G'
|
||||||
|
alias ll='ls -lGh'
|
||||||
|
alias lla='ls -lGha'
|
||||||
|
alias md5sum='md5 -r'
|
||||||
|
else
|
||||||
|
alias ls='ls --color=always'
|
||||||
|
alias ll='ls -lh --color=always'
|
||||||
|
alias lla='ls -lha --color=always'
|
||||||
|
fi
|
||||||
|
|
||||||
|
alias df='df -h'
|
||||||
|
alias du='du -h'
|
||||||
|
alias mv='mv -v'
|
||||||
|
alias cp='cp -v'
|
||||||
|
alias rm='rm -v'
|
||||||
|
alias vi='vim'
|
||||||
|
alias grepout="grep -v '^$\|^\s*\#'"
|
||||||
|
alias digs='dig +short'
|
||||||
|
|
||||||
|
|
||||||
|
function getcert () {
|
||||||
|
openssl s_client -servername ${1} -host ${1} -port 443 < /dev/null 2> /dev/null | sed -n '/BEGIN CERTIFICATE/,/END CERTIFICATE/p'
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,25 @@
|
|||||||
|
bindkey "\e[1~" beginning-of-line # Home
|
||||||
|
bindkey "\e[4~" end-of-line # End
|
||||||
|
bindkey "\e[5~" beginning-of-history # PageUp
|
||||||
|
bindkey "\e[6~" end-of-history # PageDown
|
||||||
|
bindkey "\e[2~" quoted-insert # Ins
|
||||||
|
bindkey "\e[3~" delete-char # Del
|
||||||
|
bindkey "\e[5C" forward-word
|
||||||
|
bindkey "\eOc" emacs-forward-word
|
||||||
|
bindkey "\e[5D" backward-word
|
||||||
|
bindkey "\eOd" emacs-backward-word
|
||||||
|
bindkey "\e\e[C" forward-word
|
||||||
|
bindkey "\e\e[D" backward-word
|
||||||
|
bindkey "\e[Z" reverse-menu-complete # Shift+Tab
|
||||||
|
# for rxvt
|
||||||
|
bindkey "\e[7~" beginning-of-line # Home
|
||||||
|
bindkey "\e[8~" end-of-line # End
|
||||||
|
# for non RH/Debian xterm, can't hurt for RH/Debian xterm
|
||||||
|
bindkey "\eOH" beginning-of-line
|
||||||
|
bindkey "\eOF" end-of-line
|
||||||
|
# for freebsd console
|
||||||
|
bindkey "\e[H" beginning-of-line
|
||||||
|
bindkey "\e[F" end-of-line
|
||||||
|
bindkey '^[[1;5D' emacs-backward-word
|
||||||
|
bindkey '^[[1;5C' emacs-forward-word
|
||||||
|
|
@ -0,0 +1,6 @@
|
|||||||
|
# Aliases
|
||||||
|
|
||||||
|
# Functions
|
||||||
|
|
||||||
|
# Extra Variables
|
||||||
|
|
@ -0,0 +1,7 @@
|
|||||||
|
### Set terminal title if using xterm
|
||||||
|
case $TERM in
|
||||||
|
xterm*|rxvt)
|
||||||
|
precmd () {print -Pn "\e]0;%n@%m:%~\a"}
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
@ -0,0 +1,38 @@
|
|||||||
|
#if [ -f $HOME/.zsh/color ]
|
||||||
|
#then
|
||||||
|
# source $HOME/.zsh/color
|
||||||
|
#else
|
||||||
|
# COLOR_USER=white
|
||||||
|
# COLOR_HOST=white
|
||||||
|
# COLOR_PWD=white
|
||||||
|
# COLOR_VCS=white
|
||||||
|
#fi
|
||||||
|
|
||||||
|
# GIT Prompt
|
||||||
|
autoload -Uz vcs_info
|
||||||
|
precmd_vcs_info() { vcs_info }
|
||||||
|
precmd_functions+=( precmd_vcs_info )
|
||||||
|
setopt prompt_subst
|
||||||
|
zstyle ':vcs_info:git:*' formats '[%b]'
|
||||||
|
|
||||||
|
### Old prompt format; [21:32][user@host][~/storage/git][git-branch]% [ar5]
|
||||||
|
if [ "$PROMPT_STYLE" = "ar5" ]
|
||||||
|
then
|
||||||
|
PROMPT="[%D{%H:%M}]%B%{$fg[$COLOR_USER]%}[%n@%m]%b%{$fg[$COLOR_PWD]%}[%~]%{$fg[$COLOR_VCS]%}%B\$vcs_info_msg_0_%b%{$fg[$COLOR_PWD]%}%# %{$reset_color%}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
### BSD style prompt; user@host:~/storage/git[git-branch]% [bsd]
|
||||||
|
if [ "$PROMPT_STYLE" = "bsd" ]
|
||||||
|
then
|
||||||
|
PROMPT="%B%{$fg[$COLOR_USER]%}%n@%m%b%{$reset_color%}:%{$fg[$COLOR_PWD]%}%~%{$fg[$COLOR_VCS]%}%B \$vcs_info_msg_0_%b%{$fg[$COLOR_PWD]%}%# %{$reset_color%}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
### BSD style prompt with more colours [bsd2]
|
||||||
|
if [ "$PROMPT_STYLE" = "bsd2" ]
|
||||||
|
then
|
||||||
|
PROMPT="%B%{$fg[$COLOR_USER]%}%n%{$reset_color%}%{$fg[white]%}@%B%{$fg[$COLOR_HOST]%}%m%b%{$reset_color%}:%{$fg[$COLOR_PWD]%}%~%{$fg[$COLOR_VCS]%}%B \$vcs_info_msg_0_%b%{$fg[$COLOR_PWD]%}%# %{$reset_color%}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
### UNUSED ### New style with primary-coloured %/#
|
||||||
|
#PROMPT="%B%{$fg[$COLOR_USER]%}%n@%m%b%{$reset_color%}:%{$fg[$COLOR_PWD]%}%~%{$fg[$COLOR_VCS]%}%B\$vcs_info_msg_0_%b%{$fg[$COLOR_PWD]%}%B%{$fg[$COLOR]%}%# %{$reset_color%}"
|
||||||
|
|
@ -0,0 +1,11 @@
|
|||||||
|
autoload -U compinit promptinit
|
||||||
|
autoload -U colors && colors
|
||||||
|
compinit -d ${HOME}/.cache/.zcompdump
|
||||||
|
promptinit
|
||||||
|
setopt autocd
|
||||||
|
unsetopt beep
|
||||||
|
setopt HIST_IGNORE_SPACE
|
||||||
|
|
||||||
|
## BASH-style completion; comment out for full ZSH completion.
|
||||||
|
setopt noautomenu
|
||||||
|
|
@ -0,0 +1,23 @@
|
|||||||
|
Copyright (c) 2010-2011 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.
|
@ -0,0 +1,47 @@
|
|||||||
|
zsh-syntax-highlighting
|
||||||
|
=======================
|
||||||
|
|
||||||
|
**[Fish shell](http://www.fishshell.com) like syntax highlighting for [Zsh](http://www.zsh.org).**
|
||||||
|
|
||||||
|
*Requirements: zsh 4.3.9+.*
|
||||||
|
|
||||||
|
|
||||||
|
How to install
|
||||||
|
--------------
|
||||||
|
|
||||||
|
### In your ~/.zshrc
|
||||||
|
|
||||||
|
* Download the script or clone this repository:
|
||||||
|
|
||||||
|
git clone git://github.com/zsh-users/zsh-syntax-highlighting.git
|
||||||
|
|
||||||
|
* Source the script **at the end** of `~/.zshrc`:
|
||||||
|
|
||||||
|
source /path/to/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
|
||||||
|
|
||||||
|
* 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/zsh-users/zsh-syntax-highlighting.git
|
||||||
|
|
||||||
|
* Activate the plugin in `~/.zshrc` (in **last** position):
|
||||||
|
|
||||||
|
plugins=( [plugins...] zsh-syntax-highlighting)
|
||||||
|
|
||||||
|
* Source `~/.zshrc` to take changes into account:
|
||||||
|
|
||||||
|
source ~/.zshrc
|
||||||
|
|
||||||
|
|
||||||
|
How to tweak
|
||||||
|
------------
|
||||||
|
|
||||||
|
Syntax highlighting is done by pluggable highlighter scripts, see the [highlighters directory](zsh-syntax-highlighting/tree/master/highlighters)
|
||||||
|
for documentation and configuration settings.
|
@ -0,0 +1,49 @@
|
|||||||
|
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.
|
||||||
|
|
||||||
|
|
||||||
|
How to activate highlighters
|
||||||
|
----------------------------
|
||||||
|
|
||||||
|
To activate an highlighter, add it to the `ZSH_HIGHLIGHT_HIGHLIGHTERS` array in `~/.zshrc`, for example:
|
||||||
|
|
||||||
|
ZSH_HIGHLIGHT_HIGHLIGHTERS=(main brackets pattern cursor)
|
||||||
|
|
||||||
|
|
||||||
|
How to tweak highlighters
|
||||||
|
-------------------------
|
||||||
|
|
||||||
|
Highlighters look up styles from the `ZSH_HIGHLIGHT_STYLES` array. Navigate into each highlighter directory to see what styles it defines and how to configure it.
|
||||||
|
|
||||||
|
|
||||||
|
How to implement a new highlighter
|
||||||
|
----------------------------------
|
||||||
|
|
||||||
|
To create your own ***myhighlighter*** highlighter:
|
||||||
|
|
||||||
|
* Create your script at **highlighters/*myhighlighter*/*myhighlighter*-highlighter.zsh**.
|
||||||
|
* Implement the `_zsh_highlight_myhighlighter_highlighter_predicate` function. This function must return 0 when the highlighter needs to be called, for example:
|
||||||
|
|
||||||
|
_zsh_highlight_myhighlighter_highlighter_predicate() {
|
||||||
|
# Call this highlighter in SVN repositories
|
||||||
|
[[ -d .svn ]]
|
||||||
|
}
|
||||||
|
|
||||||
|
* Implement the `_zsh_highlight_myhighlighter_highlighter` function. This function does the actual syntax highlighting, by modifying `region_highlight`, for example:
|
||||||
|
|
||||||
|
_zsh_highlight_myhighlighter_highlighter() {
|
||||||
|
# Colorize the whole buffer with blue background
|
||||||
|
region_highlight+=(0 $#BUFFER bg=blue)
|
||||||
|
}
|
||||||
|
|
||||||
|
* Activate your highlighter in `~/.zshrc`:
|
||||||
|
|
||||||
|
ZSH_HIGHLIGHT_HIGHLIGHTERS+=(myhighlighter)
|
@ -0,0 +1,30 @@
|
|||||||
|
zsh-syntax-highlighting / highlighters / brackets
|
||||||
|
=================================================
|
||||||
|
|
||||||
|
This is the ***brackets*** highlighter, that highlights brackets, parenthesis and matches them.
|
||||||
|
|
||||||
|
|
||||||
|
How to activate it
|
||||||
|
------------------
|
||||||
|
To activate it, add it to `ZSH_HIGHLIGHT_HIGHLIGHTERS`:
|
||||||
|
|
||||||
|
ZSH_HIGHLIGHT_HIGHLIGHTERS=( [...] brackets)
|
||||||
|
|
||||||
|
|
||||||
|
How to tweak it
|
||||||
|
---------------
|
||||||
|
This highlighter defines the following styles:
|
||||||
|
|
||||||
|
* `bracket-error` - unmatched brackets
|
||||||
|
* `bracket-level-N` - brackets with nest level N
|
||||||
|
* `cursor-matchingbracket` - the matching bracket, if cursor is on a bracket
|
||||||
|
|
||||||
|
To override one of those styles, change its entry in `ZSH_HIGHLIGHT_STYLES`, for example in `~/.zshrc`:
|
||||||
|
|
||||||
|
# To define styles for nested brackets up to level 4
|
||||||
|
ZSH_HIGHLIGHT_STYLES[bracket-level-1]='fg=blue,bold'
|
||||||
|
ZSH_HIGHLIGHT_STYLES[bracket-level-2]='fg=red,bold'
|
||||||
|
ZSH_HIGHLIGHT_STYLES[bracket-level-3]='fg=yellow,bold'
|
||||||
|
ZSH_HIGHLIGHT_STYLES[bracket-level-4]='fg=magenta,bold'
|
||||||
|
|
||||||
|
The syntax for declaring styles is [documented here](http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#SEC135).
|
@ -0,0 +1,110 @@
|
|||||||
|
#!/usr/bin/env zsh
|
||||||
|
# -------------------------------------------------------------------------------------------------
|
||||||
|
# Copyright (c) 2010-2011 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
|
||||||
|
# -------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
# 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_brackets_highlighter_predicate()
|
||||||
|
{
|
||||||
|
_zsh_highlight_cursor_moved || _zsh_highlight_buffer_modified
|
||||||
|
}
|
||||||
|
|
||||||
|
# Brackets highlighting function.
|
||||||
|
_zsh_highlight_brackets_highlighter()
|
||||||
|
{
|
||||||
|
local level=0 pos
|
||||||
|
local -A levelpos lastoflevel matching typepos
|
||||||
|
|
||||||
|
# Find all brackets and remember which one is matching
|
||||||
|
for (( pos = 0; $pos < ${#BUFFER}; pos++ )) ; do
|
||||||
|
local char=$BUFFER[pos+1]
|
||||||
|
case $char in
|
||||||
|
["([{"])
|
||||||
|
levelpos[$pos]=$((++level))
|
||||||
|
lastoflevel[$level]=$pos
|
||||||
|
_zsh_highlight_brackets_highlighter_brackettype $char
|
||||||
|
;;
|
||||||
|
[")]}"])
|
||||||
|
matching[$lastoflevel[$level]]=$pos
|
||||||
|
matching[$pos]=$lastoflevel[$level]
|
||||||
|
levelpos[$pos]=$((level--))
|
||||||
|
_zsh_highlight_brackets_highlighter_brackettype $char
|
||||||
|
;;
|
||||||
|
['"'\'])
|
||||||
|
# Skip everything inside quotes
|
||||||
|
local quotetype=$char
|
||||||
|
while (( $pos < ${#BUFFER} )) ; do
|
||||||
|
(( pos++ ))
|
||||||
|
[[ $BUFFER[$pos+1] == $quotetype ]] && break
|
||||||
|
done
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
# Now highlight all found brackets
|
||||||
|
for pos in ${(k)levelpos}; do
|
||||||
|
if [[ -n $matching[$pos] ]] && [[ $typepos[$pos] == $typepos[$matching[$pos]] ]]; then
|
||||||
|
local bracket_color_size=${#ZSH_HIGHLIGHT_STYLES[(I)bracket-level-*]}
|
||||||
|
local bracket_color_level=bracket-level-$(( (levelpos[$pos] - 1) % bracket_color_size + 1 ))
|
||||||
|
local style=$ZSH_HIGHLIGHT_STYLES[$bracket_color_level]
|
||||||
|
region_highlight+=("$pos $((pos + 1)) $style")
|
||||||
|
else
|
||||||
|
local style=$ZSH_HIGHLIGHT_STYLES[bracket-error]
|
||||||
|
region_highlight+=("$pos $((pos + 1)) $style")
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
# If cursor is on a bracket, then highlight corresponding bracket, if any
|
||||||
|
pos=$CURSOR
|
||||||
|
if [[ -n $levelpos[$pos] ]] && [[ -n $matching[$pos] ]]; then
|
||||||
|
local otherpos=$matching[$pos]
|
||||||
|
local style=$ZSH_HIGHLIGHT_STYLES[cursor-matchingbracket]
|
||||||
|
region_highlight+=("$otherpos $((otherpos + 1)) $style")
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Helper function to differentiate type
|
||||||
|
_zsh_highlight_brackets_highlighter_brackettype()
|
||||||
|
{
|
||||||
|
case $1 in
|
||||||
|
["()"]) typepos[$pos]=round;;
|
||||||
|
["[]"]) typepos[$pos]=bracket;;
|
||||||
|
["{}"]) typepos[$pos]=curly;;
|
||||||
|
*) ;;
|
||||||
|
esac
|
||||||
|
}
|
@ -0,0 +1,38 @@
|
|||||||
|
#!/usr/bin/env zsh
|
||||||
|
# -------------------------------------------------------------------------------------------------
|
||||||
|
# Copyright (c) 2010-2011 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
|
||||||
|
# -------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
BUFFER='echo ({x}]'
|
||||||
|
|
||||||
|
expected_region_highlight=(
|
||||||
|
"5 5 $ZSH_HIGHLIGHT_STYLES[bracket-error]" # (
|
||||||
|
"6 6 $ZSH_HIGHLIGHT_STYLES[bracket-level-2]" # {
|
||||||
|
"8 8 $ZSH_HIGHLIGHT_STYLES[bracket-level-2]" # }
|
||||||
|
"9 9 $ZSH_HIGHLIGHT_STYLES[bracket-error]" # )
|
||||||
|
)
|
@ -0,0 +1,40 @@
|
|||||||
|
#!/usr/bin/env zsh
|
||||||
|
# -------------------------------------------------------------------------------------------------
|
||||||
|
# Copyright (c) 2010-2011 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
|
||||||
|
# -------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
BUFFER='echo $(echo ${(z)array})'
|
||||||
|
|
||||||
|
expected_region_highlight=(
|
||||||
|
"6 6 $ZSH_HIGHLIGHT_STYLES[bracket-level-1]" # (
|
||||||
|
"13 13 $ZSH_HIGHLIGHT_STYLES[bracket-level-2]" # {
|
||||||
|
"14 14 $ZSH_HIGHLIGHT_STYLES[bracket-level-3]" # (
|
||||||
|
"16 16 $ZSH_HIGHLIGHT_STYLES[bracket-level-3]" # )
|
||||||
|
"22 22 $ZSH_HIGHLIGHT_STYLES[bracket-level-2]" # }
|
||||||
|
"23 23 $ZSH_HIGHLIGHT_STYLES[bracket-level-1]" # )
|
||||||
|
)
|
@ -0,0 +1,35 @@
|
|||||||
|
#!/usr/bin/env zsh
|
||||||
|
# -------------------------------------------------------------------------------------------------
|
||||||
|
# Copyright (c) 2010-2011 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
|
||||||
|
# -------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
BUFFER='echo "foo ( bar"'
|
||||||
|
|
||||||
|
expected_region_highlight=(
|
||||||
|
"1 15 $ZSH_HIGHLIGHT_STYLES[none]" # We expect the brackets highlighter to do nothing
|
||||||
|
)
|
@ -0,0 +1,38 @@
|
|||||||
|
#!/usr/bin/env zsh
|
||||||
|
# -------------------------------------------------------------------------------------------------
|
||||||
|
# Copyright (c) 2010-2011 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
|
||||||
|
# -------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
BUFFER='echo ({x})'
|
||||||
|
|
||||||
|
expected_region_highlight=(
|
||||||
|
"5 5 $ZSH_HIGHLIGHT_STYLES[bracket-level-1]" # (
|
||||||
|
"6 6 $ZSH_HIGHLIGHT_STYLES[bracket-level-2]" # {
|
||||||
|
"8 8 $ZSH_HIGHLIGHT_STYLES[bracket-level-2]" # }
|
||||||
|
"9 9 $ZSH_HIGHLIGHT_STYLES[bracket-level-1]" # )
|
||||||
|
)
|
@ -0,0 +1,37 @@
|
|||||||
|
#!/usr/bin/env zsh
|
||||||
|
# -------------------------------------------------------------------------------------------------
|
||||||
|
# Copyright (c) 2010-2011 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
|
||||||
|
# -------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
BUFFER='echo ({x}'
|
||||||
|
|
||||||
|
expected_region_highlight=(
|
||||||
|
"5 5 $ZSH_HIGHLIGHT_STYLES[bracket-error]" # (
|
||||||
|
"6 6 $ZSH_HIGHLIGHT_STYLES[bracket-level-2]" # {
|
||||||
|
"8 8 $ZSH_HIGHLIGHT_STYLES[bracket-level-2]" # }
|
||||||
|
)
|
@ -0,0 +1,37 @@
|
|||||||
|
#!/usr/bin/env zsh
|
||||||
|
# -------------------------------------------------------------------------------------------------
|
||||||
|
# Copyright (c) 2010-2011 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
|
||||||
|
# -------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
BUFFER='echo {x})'
|
||||||
|
|
||||||
|
expected_region_highlight=(
|
||||||
|
"5 5 $ZSH_HIGHLIGHT_STYLES[bracket-level-1]" # {
|
||||||
|
"7 7 $ZSH_HIGHLIGHT_STYLES[bracket-level-1]" # }
|
||||||
|
"8 8 $ZSH_HIGHLIGHT_STYLES[bracket-error]" # )
|
||||||
|
)
|
@ -0,0 +1,24 @@
|
|||||||
|
zsh-syntax-highlighting / highlighters / cursor
|
||||||
|
=================================================
|
||||||
|
|
||||||
|
This is the ***cursor*** highlighter, that highlights the cursor.
|
||||||
|
|
||||||
|
|
||||||
|
How to activate it
|
||||||
|
------------------
|
||||||
|
To activate it, add it to `ZSH_HIGHLIGHT_HIGHLIGHTERS`:
|
||||||
|
|
||||||
|
ZSH_HIGHLIGHT_HIGHLIGHTERS=( [...] cursor)
|
||||||
|
|
||||||
|
|
||||||
|
How to tweak it
|
||||||
|
---------------
|
||||||
|
This highlighter defines the following styles:
|
||||||
|
|
||||||
|
* `cursor` - the style for the current cursor position
|
||||||
|
|
||||||
|
To override one of those styles, change its entry in `ZSH_HIGHLIGHT_STYLES`, for example in `~/.zshrc`:
|
||||||
|
|
||||||
|
ZSH_HIGHLIGHT_STYLES[cursor]='bg=blue'
|
||||||
|
|
||||||
|
The syntax for declaring styles is [documented here](http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#SEC135).
|
@ -0,0 +1,45 @@
|
|||||||
|
#!/usr/bin/env zsh
|
||||||
|
# -------------------------------------------------------------------------------------------------
|
||||||
|
# Copyright (c) 2010-2011 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
|
||||||
|
# -------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
# Define default styles.
|
||||||
|
: ${ZSH_HIGHLIGHT_STYLES[cursor]:=standout}
|
||||||
|
|
||||||
|
# Whether the cursor highlighter should be called or not.
|
||||||
|
_zsh_highlight_cursor_highlighter_predicate()
|
||||||
|
{
|
||||||
|
_zsh_highlight_cursor_moved
|
||||||
|
}
|
||||||
|
|
||||||
|
# Cursor highlighting function.
|
||||||
|
_zsh_highlight_cursor_highlighter()
|
||||||
|
{
|
||||||
|
region_highlight+=("$CURSOR $(( $CURSOR + 1 )) $ZSH_HIGHLIGHT_STYLES[cursor]")
|
||||||
|
}
|
@ -0,0 +1,58 @@
|
|||||||
|
zsh-syntax-highlighting / highlighters / main
|
||||||
|
=============================================
|
||||||
|
|
||||||
|
This is the ***main*** highlighter, that highlights:
|
||||||
|
|
||||||
|
* Commands
|
||||||
|
* Options
|
||||||
|
* Arguments
|
||||||
|
* Paths
|
||||||
|
* Strings
|
||||||
|
|
||||||
|
How to activate it
|
||||||
|
------------------
|
||||||
|
To activate it, add it to `ZSH_HIGHLIGHT_HIGHLIGHTERS`:
|
||||||
|
|
||||||
|
ZSH_HIGHLIGHT_HIGHLIGHTERS=( [...] main)
|
||||||
|
|
||||||
|
This highlighter is active by default.
|
||||||
|
|
||||||
|
|
||||||
|
How to tweak it
|
||||||
|
---------------
|
||||||
|
This highlighter defines the following styles:
|
||||||
|
|
||||||
|
* `unknown-token` - unknown tokens / errors
|
||||||
|
* `reserved-word` - shell reserved words
|
||||||
|
* `alias` - aliases
|
||||||
|
* `builtin` - shell builtin commands
|
||||||
|
* `function` - functions
|
||||||
|
* `command` - commands
|
||||||
|
* `precommand` - precommands (i.e. exec, builtin, ...)
|
||||||
|
* `commandseparator` - command separation tokens
|
||||||
|
* `hashed-command` - hashed commands
|
||||||
|
* `path` - paths
|
||||||
|
* `globbing` - globbing expressions
|
||||||
|
* `history-expansion` - history expansion expressions
|
||||||
|
* `single-hyphen-option` - single hyphen options
|
||||||
|
* `double-hyphen-option` - double hyphen options
|
||||||
|
* `back-quoted-argument` - backquoted expressions
|
||||||
|
* `single-quoted-argument` - single quoted arguments
|
||||||
|
* `double-quoted-argument` - double quoted arguments
|
||||||
|
* `dollar-double-quoted-argument` - dollar double quoted arguments
|
||||||
|
* `back-double-quoted-argument` - back double quoted arguments
|
||||||
|
* `assign` - variable assignments
|
||||||
|
* `default` - parts of the buffer that do not match anything
|
||||||
|
|
||||||
|
To override one of those styles, change its entry in `ZSH_HIGHLIGHT_STYLES`, for example in `~/.zshrc`:
|
||||||
|
|
||||||
|
# To differentiate 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'
|
||||||
|
|
||||||
|
The syntax for declaring styles is [documented here](http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#SEC135).
|
@ -0,0 +1,184 @@
|
|||||||
|
#!/usr/bin/env zsh
|
||||||
|
# -------------------------------------------------------------------------------------------------
|
||||||
|
# Copyright (c) 2010-2011 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
|
||||||
|
# -------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
# 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[alias]:=fg=green}
|
||||||
|
: ${ZSH_HIGHLIGHT_STYLES[builtin]:=fg=green}
|
||||||
|
: ${ZSH_HIGHLIGHT_STYLES[function]:=fg=green}
|
||||||
|
: ${ZSH_HIGHLIGHT_STYLES[command]:=fg=green}
|
||||||
|
: ${ZSH_HIGHLIGHT_STYLES[precommand]:=fg=green,none}
|
||||||
|
: ${ZSH_HIGHLIGHT_STYLES[commandseparator]:=none}
|
||||||
|
: ${ZSH_HIGHLIGHT_STYLES[hashed-command]:=fg=green}
|
||||||
|
: ${ZSH_HIGHLIGHT_STYLES[path]:=none}
|
||||||
|
: ${ZSH_HIGHLIGHT_STYLES[globbing]:=fg=blue}
|
||||||
|
: ${ZSH_HIGHLIGHT_STYLES[history-expansion]:=fg=blue}
|
||||||
|
: ${ZSH_HIGHLIGHT_STYLES[single-hyphen-option]:=none}
|
||||||
|
: ${ZSH_HIGHLIGHT_STYLES[double-hyphen-option]:=none}
|
||||||
|
: ${ZSH_HIGHLIGHT_STYLES[back-quoted-argument]:=none}
|
||||||
|
: ${ZSH_HIGHLIGHT_STYLES[single-quoted-argument]:=fg=yellow}
|
||||||
|
: ${ZSH_HIGHLIGHT_STYLES[double-quoted-argument]:=fg=yellow}
|
||||||
|
: ${ZSH_HIGHLIGHT_STYLES[dollar-double-quoted-argument]:=fg=cyan}
|
||||||
|
: ${ZSH_HIGHLIGHT_STYLES[back-double-quoted-argument]:=fg=cyan}
|
||||||
|
: ${ZSH_HIGHLIGHT_STYLES[assign]:=none}
|
||||||
|
|
||||||
|
# Whether the highlighter should be called or not.
|
||||||
|
_zsh_highlight_main_highlighter_predicate()
|
||||||
|
{
|
||||||
|
_zsh_highlight_buffer_modified
|
||||||
|
}
|
||||||
|
|
||||||
|
# Main syntax highlighting function.
|
||||||
|
_zsh_highlight_main_highlighter()
|
||||||
|
{
|
||||||
|
setopt localoptions extendedglob bareglobqual
|
||||||
|
local start_pos=0 end_pos highlight_glob=true new_expression=true arg style
|
||||||
|
typeset -a ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR
|
||||||
|
typeset -a ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS
|
||||||
|
typeset -a ZSH_HIGHLIGHT_TOKENS_FOLLOWED_BY_COMMANDS
|
||||||
|
region_highlight=()
|
||||||
|
|
||||||
|
ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR=(
|
||||||
|
'|' '||' ';' '&' '&&'
|
||||||
|
)
|
||||||
|
ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS=(
|
||||||
|
'builtin' 'command' 'exec' 'nocorrect' 'noglob'
|
||||||
|
)
|
||||||
|
# Tokens that are always immediately followed by a command.
|
||||||
|
ZSH_HIGHLIGHT_TOKENS_FOLLOWED_BY_COMMANDS=(
|
||||||
|
$ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR $ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS
|
||||||
|
)
|
||||||
|
|
||||||
|
for arg in ${(z)BUFFER}; do
|
||||||
|
local substr_color=0
|
||||||
|
[[ $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}))
|
||||||
|
if $new_expression; then
|
||||||
|
new_expression=false
|
||||||
|
if [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS:#"$arg"} ]]; then
|
||||||
|
style=$ZSH_HIGHLIGHT_STYLES[precommand]
|
||||||
|
else
|
||||||
|
res=$(LC_ALL=C builtin type -w $arg 2>/dev/null)
|
||||||
|
case $res in
|
||||||
|
*': reserved') style=$ZSH_HIGHLIGHT_STYLES[reserved-word];;
|
||||||
|
*': alias') style=$ZSH_HIGHLIGHT_STYLES[alias]
|
||||||
|
local aliased_command="${"$(alias $arg)"#*=}"
|
||||||
|
[[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_FOLLOWED_BY_COMMANDS:#"$aliased_command"} && -z ${(M)ZSH_HIGHLIGHT_TOKENS_FOLLOWED_BY_COMMANDS:#"$arg"} ]] && ZSH_HIGHLIGHT_TOKENS_FOLLOWED_BY_COMMANDS+=($arg)
|
||||||
|
;;
|
||||||
|
*': builtin') style=$ZSH_HIGHLIGHT_STYLES[builtin];;
|
||||||
|
*': function') style=$ZSH_HIGHLIGHT_STYLES[function];;
|
||||||
|
*': command') style=$ZSH_HIGHLIGHT_STYLES[command];;
|
||||||
|
*': hashed') style=$ZSH_HIGHLIGHT_STYLES[hashed-command];;
|
||||||
|
*) if _zsh_highlight_main_highlighter_check_assign; then
|
||||||
|
style=$ZSH_HIGHLIGHT_STYLES[assign]
|
||||||
|
new_expression=true
|
||||||
|
elif _zsh_highlight_main_highlighter_check_path; then
|
||||||
|
style=$ZSH_HIGHLIGHT_STYLES[path]
|
||||||
|
elif [[ $arg[0,1] = $histchars[0,1] ]]; then
|
||||||
|
style=$ZSH_HIGHLIGHT_STYLES[history-expansion]
|
||||||
|
else
|
||||||
|
style=$ZSH_HIGHLIGHT_STYLES[unknown-token]
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
case $arg in
|
||||||
|
'--'*) 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_main_highlighter_highlight_string
|
||||||
|
substr_color=1
|
||||||
|
;;
|
||||||
|
'`'*'`') style=$ZSH_HIGHLIGHT_STYLES[back-quoted-argument];;
|
||||||
|
*"*"*) $highlight_glob && style=$ZSH_HIGHLIGHT_STYLES[globbing] || style=$ZSH_HIGHLIGHT_STYLES[default];;
|
||||||
|
*) if _zsh_highlight_main_highlighter_check_path; then
|
||||||
|
style=$ZSH_HIGHLIGHT_STYLES[path]
|
||||||
|
elif [[ $arg[0,1] = $histchars[0,1] ]]; then
|
||||||
|
style=$ZSH_HIGHLIGHT_STYLES[history-expansion]
|
||||||
|
elif [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR:#"$arg"} ]]; then
|
||||||
|
style=$ZSH_HIGHLIGHT_STYLES[commandseparator]
|
||||||
|
else
|
||||||
|
style=$ZSH_HIGHLIGHT_STYLES[default]
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
fi
|
||||||
|
[[ $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
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
# Check if the argument is variable assignment
|
||||||
|
_zsh_highlight_main_highlighter_check_assign()
|
||||||
|
{
|
||||||
|
setopt localoptions extended_glob
|
||||||
|
[[ ${(Q)arg} == [[:alpha:]_]([[:alnum:]_])#=* ]]
|
||||||
|
}
|
||||||
|
|
||||||
|
# Check if the argument is a path.
|
||||||
|
_zsh_highlight_main_highlighter_check_path()
|
||||||
|
{
|
||||||
|
setopt localoptions nonomatch
|
||||||
|
local expanded_path; : ${expanded_path:=${(Q)~arg}}
|
||||||
|
[[ -z $expanded_path ]] && return 1
|
||||||
|
[[ -e $expanded_path ]] && return 0
|
||||||
|
[[ ! -e ${expanded_path:h} ]] && return 1
|
||||||
|
[[ ${BUFFER[1]} != "-" && ${#BUFFER} == $end_pos && -n $(print ${expanded_path}*(N)) ]] && return 0
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# Highlight special chars inside double-quoted strings
|
||||||
|
_zsh_highlight_main_highlighter_highlight_string()
|
||||||
|
{
|
||||||
|
setopt localoptions noksharrays
|
||||||
|
local i j k style
|
||||||
|
# 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.
|
||||||
|
;;
|
||||||
|
*) continue;;
|
||||||
|
esac
|
||||||
|
region_highlight+=("$j $k $style")
|
||||||
|
done
|
||||||
|
}
|
@ -0,0 +1,35 @@
|
|||||||
|
#!/usr/bin/env zsh
|
||||||
|
# -------------------------------------------------------------------------------------------------
|
||||||
|
# Copyright (c) 2010-2011 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
|
||||||
|
# -------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
BUFFER='A=1'
|
||||||
|
|
||||||
|
expected_region_highlight=(
|
||||||
|
"1 3 $ZSH_HIGHLIGHT_STYLES[assign]" # A=1
|
||||||
|
)
|
@ -0,0 +1,47 @@
|
|||||||
|
#!/usr/bin/env zsh
|
||||||
|
# -------------------------------------------------------------------------------------------------
|
||||||
|
# Copyright (c) 2010-2011 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
|
||||||
|
# -------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
BUFFER='ps aux | grep java | sort | uniq | tail | head'
|
||||||
|
|
||||||
|
expected_region_highlight=(
|
||||||
|
"1 2 $ZSH_HIGHLIGHT_STYLES[command]" # ps
|
||||||
|
"4 6 $ZSH_HIGHLIGHT_STYLES[default]" # aux
|
||||||
|
"8 8 $ZSH_HIGHLIGHT_STYLES[default]" # |
|
||||||
|
"10 13 $ZSH_HIGHLIGHT_STYLES[command]" # grep
|
||||||
|
"15 18 $ZSH_HIGHLIGHT_STYLES[default]" # java
|
||||||
|
"20 20 $ZSH_HIGHLIGHT_STYLES[default]" # |
|
||||||
|
"22 25 $ZSH_HIGHLIGHT_STYLES[command]" # sort
|
||||||
|
"27 27 $ZSH_HIGHLIGHT_STYLES[default]" # |
|
||||||
|
"29 32 $ZSH_HIGHLIGHT_STYLES[command]" # uniq
|
||||||
|
"34 34 $ZSH_HIGHLIGHT_STYLES[default]" # |
|
||||||
|
"36 39 $ZSH_HIGHLIGHT_STYLES[command]" # tail
|
||||||
|
"41 41 $ZSH_HIGHLIGHT_STYLES[default]" # |
|
||||||
|
"43 46 $ZSH_HIGHLIGHT_STYLES[command]" # head
|
||||||
|
)
|
@ -0,0 +1,36 @@
|
|||||||
|
#!/usr/bin/env zsh
|
||||||
|
# -------------------------------------------------------------------------------------------------
|
||||||
|
# Copyright (c) 2010-2011 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
|
||||||
|
# -------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
BUFFER='ls highlighters/main/test-data/path-space-\ .zsh'
|
||||||
|
|
||||||
|
expected_region_highlight=(
|
||||||
|
"1 2 $ZSH_HIGHLIGHT_STYLES[command]" # ls
|
||||||
|
"4 48 $ZSH_HIGHLIGHT_STYLES[path]" # highlighters/main/test-data/path-space-\ .zsh
|
||||||
|
)
|
@ -0,0 +1,36 @@
|
|||||||
|
#!/usr/bin/env zsh
|
||||||
|
# -------------------------------------------------------------------------------------------------
|
||||||
|
# Copyright (c) 2010-2011 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
|
||||||
|
# -------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
BUFFER='ls ~'
|
||||||
|
|
||||||
|
expected_region_highlight=(
|
||||||
|
"1 2 $ZSH_HIGHLIGHT_STYLES[command]" # ls
|
||||||
|
"4 4 $ZSH_HIGHLIGHT_STYLES[path]" # ~
|
||||||
|
)
|
@ -0,0 +1,38 @@
|
|||||||
|
#!/usr/bin/env zsh
|
||||||
|
# -------------------------------------------------------------------------------------------------
|
||||||
|
# Copyright (c) 2010-2011 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
|
||||||
|
# -------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
hash -d D=highlighters/main/test-data
|
||||||
|
|
||||||
|
BUFFER='ls ~D/path-tilde-named.zsh'
|
||||||
|
|
||||||
|
expected_region_highlight=(
|
||||||
|
"1 2 $ZSH_HIGHLIGHT_STYLES[command]" # ls
|
||||||
|
"4 23 $ZSH_HIGHLIGHT_STYLES[path]" # ~D/path-tilde-named.zsh
|
||||||
|
)
|
@ -0,0 +1,36 @@
|
|||||||
|
#!/usr/bin/env zsh
|
||||||
|
# -------------------------------------------------------------------------------------------------
|
||||||
|
# Copyright (c) 2010-2011 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
|
||||||
|
# -------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
BUFFER='ls highlighters/main/test-data/path.zsh'
|
||||||
|
|
||||||
|
expected_region_highlight=(
|
||||||
|
"1 2 $ZSH_HIGHLIGHT_STYLES[command]" # ls
|
||||||
|
"4 39 $ZSH_HIGHLIGHT_STYLES[path]" # highlighters/main/test-data/path.zsh
|
||||||
|
)
|
@ -0,0 +1,35 @@
|
|||||||
|
#!/usr/bin/env zsh
|
||||||
|
# -------------------------------------------------------------------------------------------------
|
||||||
|
# Copyright (c) 2010-2011 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
|
||||||
|
# -------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
BUFFER='ls'
|
||||||
|
|
||||||
|
expected_region_highlight=(
|
||||||
|
"1 2 $ZSH_HIGHLIGHT_STYLES[command]" # ls
|
||||||
|
)
|
@ -0,0 +1,39 @@
|
|||||||
|
#!/usr/bin/env zsh
|
||||||
|
# -------------------------------------------------------------------------------------------------
|
||||||
|
# Copyright (c) 2010-2011 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
|
||||||
|
# -------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
BUFFER='ps aux | grep java'
|
||||||
|
|
||||||
|
expected_region_highlight=(
|
||||||
|
"1 2 $ZSH_HIGHLIGHT_STYLES[command]" # ps
|
||||||
|
"4 6 $ZSH_HIGHLIGHT_STYLES[default]" # aux
|
||||||
|
"8 8 $ZSH_HIGHLIGHT_STYLES[default]" # |
|
||||||
|
"9 12 $ZSH_HIGHLIGHT_STYLES[command]" # grep
|
||||||
|
"14 17 $ZSH_HIGHLIGHT_STYLES[default]" # java
|
||||||
|
)
|
@ -0,0 +1,35 @@
|
|||||||
|
#!/usr/bin/env zsh
|
||||||
|
# -------------------------------------------------------------------------------------------------
|
||||||
|
# Copyright (c) 2010-2011 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
|
||||||
|
# -------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
BUFFER='azertyuiop'
|
||||||
|
|
||||||
|
expected_region_highlight=(
|
||||||
|
"1 10 $ZSH_HIGHLIGHT_STYLES[unknown-token]" # azertyuiop
|
||||||
|
)
|
@ -0,0 +1,21 @@
|
|||||||
|
zsh-syntax-highlighting / highlighters / pattern
|
||||||
|
================================================
|
||||||
|
|
||||||
|
This is the ***pattern*** highlighter, that highlights user defined patterns.
|
||||||
|
|
||||||
|
|
||||||
|
How to activate it
|
||||||
|
------------------
|
||||||
|
To activate it, add it to `ZSH_HIGHLIGHT_HIGHLIGHTERS`:
|
||||||
|
|
||||||
|
ZSH_HIGHLIGHT_HIGHLIGHTERS=( [...] pattern)
|
||||||
|
|
||||||
|
|
||||||
|
How to tweak it
|
||||||
|
---------------
|
||||||
|
To use this highlighter, associate patterns with styles in the `ZSH_HIGHLIGHT_PATTERNS` array, for example in `~/.zshrc`:
|
||||||
|
|
||||||
|
# To have commands starting with `rm -rf` in red:
|
||||||
|
ZSH_HIGHLIGHT_PATTERNS+=('rm -rf *' 'fg=white,bold,bg=red')
|
||||||
|
|
||||||
|
The syntax for declaring styles is [documented here](http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#SEC135).
|
@ -0,0 +1,59 @@
|
|||||||
|
#!/usr/bin/env zsh
|
||||||
|
# -------------------------------------------------------------------------------------------------
|
||||||
|
# Copyright (c) 2010-2011 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
|
||||||
|
# -------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
# List of keyword and color pairs.
|
||||||
|
typeset -gA ZSH_HIGHLIGHT_PATTERNS
|
||||||
|
|
||||||
|
# Whether the pattern highlighter should be called or not.
|
||||||
|
_zsh_highlight_pattern_highlighter_predicate()
|
||||||
|
{
|
||||||
|
_zsh_highlight_buffer_modified
|
||||||
|
}
|
||||||
|
|
||||||
|
# Pattern syntax highlighting function.
|
||||||
|
_zsh_highlight_pattern_highlighter()
|
||||||
|
{
|
||||||
|
setopt localoptions extendedglob
|
||||||
|
for pattern in ${(k)ZSH_HIGHLIGHT_PATTERNS}; do
|
||||||
|
_zsh_highlight_pattern_highlighter_loop "$BUFFER" "$pattern"
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
_zsh_highlight_pattern_highlighter_loop()
|
||||||
|
{
|
||||||
|
# This does *not* do its job syntactically, sorry.
|
||||||
|
local buf="$1" pat="$2"
|
||||||
|
local -a match mbegin mend
|
||||||
|
if [[ "$buf" == (#b)(*)(${~pat})* ]]; then
|
||||||
|
region_highlight+=("$((mbegin[2] - 1)) $mend[2] $ZSH_HIGHLIGHT_PATTERNS[$pat]")
|
||||||
|
"$0" "$match[1]" "$pat"; return $?
|
||||||
|
fi
|
||||||
|
}
|
@ -0,0 +1,24 @@
|
|||||||
|
zsh-syntax-highlighting / highlighters / root
|
||||||
|
=================================================
|
||||||
|
|
||||||
|
This is the ***root*** highlighter, that highlights the whole line if the current user is root.
|
||||||
|
|
||||||
|
|
||||||
|
How to activate it
|
||||||
|
------------------
|
||||||
|
To activate it, add it to `ZSH_HIGHLIGHT_HIGHLIGHTERS`:
|
||||||
|
|
||||||
|
ZSH_HIGHLIGHT_HIGHLIGHTERS=( [...] root)
|
||||||
|
|
||||||
|
|
||||||
|
How to tweak it
|
||||||
|
---------------
|
||||||
|
This highlighter defines the following styles:
|
||||||
|
|
||||||
|
* `root` - the style for the whole line if the current user is root.
|
||||||
|
|
||||||
|
To override one of those styles, change its entry in `ZSH_HIGHLIGHT_STYLES`, for example in `~/.zshrc`:
|
||||||
|
|
||||||
|
ZSH_HIGHLIGHT_STYLES[root]='bg=red'
|
||||||
|
|
||||||
|
The syntax for declaring styles is [documented here](http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#SEC135).
|
@ -0,0 +1,45 @@
|
|||||||
|
#!/usr/bin/env zsh
|
||||||
|
# -------------------------------------------------------------------------------------------------
|
||||||
|
# Copyright (c) 2010-2011 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
|
||||||
|
# -------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
# Define default styles.
|
||||||
|
: ${ZSH_HIGHLIGHT_STYLES[root]:=standout}
|
||||||
|
|
||||||
|
# Whether the root highlighter should be called or not.
|
||||||
|
_zsh_highlight_root_highlighter_predicate()
|
||||||
|
{
|
||||||
|
_zsh_highlight_buffer_modified
|
||||||
|
}
|
||||||
|
|
||||||
|
# root highlighting function.
|
||||||
|
_zsh_highlight_root_highlighter()
|
||||||
|
{
|
||||||
|
[[ $(command id -u) -eq 0 ]] && region_highlight+=("0 $#BUFFER $ZSH_HIGHLIGHT_STYLES[root]")
|
||||||
|
}
|
@ -0,0 +1,20 @@
|
|||||||
|
zsh-syntax-highlighting / tests
|
||||||
|
===============================
|
||||||
|
|
||||||
|
Utility scripts for testing zsh-syntax-highlighting highlighters.
|
||||||
|
|
||||||
|
The tests expect the highlighter directory to contain a `test-data` directory with test data files. See the [main highlighter](../highlighters/main/test-data) for examples.
|
||||||
|
|
||||||
|
|
||||||
|
highlighting test
|
||||||
|
-----------------
|
||||||
|
[`test-highlighting.zsh`](tests/test-highlighting.zsh) tests the correctness of the highlighting. Usage:
|
||||||
|
|
||||||
|
zsh test-highlighting.zsh <HIGHLIGHTER NAME>
|
||||||
|
|
||||||
|
|
||||||
|
performance test
|
||||||
|
----------------
|
||||||
|
[`test-perfs.zsh`](tests/test-perfs.zsh) measures the time spent doing the highlighting. Usage:
|
||||||
|
|
||||||
|
zsh test-perfs.zsh <HIGHLIGHTER NAME>
|
@ -0,0 +1,115 @@
|
|||||||
|
#!/usr/bin/env zsh
|
||||||
|
# -------------------------------------------------------------------------------------------------
|
||||||
|
# Copyright (c) 2010-2011 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
|
||||||
|
# -------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
# Check an highlighter was given as argument.
|
||||||
|
[[ -n "$1" ]] || {
|
||||||
|
echo "You must provide the name of a valid highlighter as argument." >&2
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# Check the highlighter is valid.
|
||||||
|
[[ -f ${0:h:h}/highlighters/$1/$1-highlighter.zsh ]] || {
|
||||||
|
echo "Could not find highlighter '$1'." >&2
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# Check the highlighter has test data.
|
||||||
|
[[ -d ${0:h:h}/highlighters/$1/test-data ]] || {
|
||||||
|
echo "Highlighter '$1' has no test data." >&2
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
local -a errors highlight_zone
|
||||||
|
local -A observed_result
|
||||||
|
|
||||||
|
# Load the main script.
|
||||||
|
. ${0:h:h}/zsh-syntax-highlighting.zsh
|
||||||
|
|
||||||
|
# Activate the highlighter.
|
||||||
|
ZSH_HIGHLIGHT_HIGHLIGHTERS=($1)
|
||||||
|
|
||||||
|
# Process each test data file in test data directory.
|
||||||
|
for data_file in ${0:h:h}/highlighters/$1/test-data/*; do
|
||||||
|
|
||||||
|
# Load the data and prepare checking it.
|
||||||
|
BUFFER= ; expected_region_highlight=(); errors=()
|
||||||
|
echo -n "* ${data_file:t:r}: "
|
||||||
|
. $data_file
|
||||||
|
|
||||||
|
# Check the data declares $BUFFER.
|
||||||
|
if [[ ${#BUFFER} -eq 0 ]]; then
|
||||||
|
errors+=("'BUFFER' is not declared or blank.")
|
||||||
|
else
|
||||||
|
|
||||||
|
# Check the data declares $expected_region_highlight.
|
||||||
|
if [[ ${#expected_region_highlight} -eq 0 ]]; then
|
||||||
|
errors+=("'expected_region_highlight' is not declared or empty.")
|
||||||
|
else
|
||||||
|
|
||||||
|
# Process the data.
|
||||||
|
region_highlight=()
|
||||||
|
_zsh_highlight
|
||||||
|
|
||||||
|
# Overlapping regions can be declared in region_highlight, so we first build an array of the
|
||||||
|
# observed highlighting.
|
||||||
|
observed_result=()
|
||||||
|
for i in {1..${#region_highlight}}; do
|
||||||
|
highlight_zone=${(z)region_highlight[$i]}
|
||||||
|
for j in {$highlight_zone[1]..$highlight_zone[2]}; do
|
||||||
|
observed_result[$j]=$highlight_zone[3]
|
||||||
|
done
|
||||||
|
done
|
||||||
|
|
||||||
|
# Then we compare the observed result with the expected one.
|
||||||
|
for i in {1..${#expected_region_highlight}}; do
|
||||||
|
highlight_zone=${(z)expected_region_highlight[$i]}
|
||||||
|
for j in {$highlight_zone[1]..$highlight_zone[2]}; do
|
||||||
|
if [[ "$observed_result[$j]" != "$highlight_zone[3]" ]]; then
|
||||||
|
errors+=("'$BUFFER[$highlight_zone[1],$highlight_zone[2]]' [$highlight_zone[1],$highlight_zone[2]]: expected '$highlight_zone[3]', observed '$observed_result[$j]'.")
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
done
|
||||||
|
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Format result/errors.
|
||||||
|
if [[ ${#errors} -eq 0 ]]; then
|
||||||
|
echo "OK"
|
||||||
|
else
|
||||||
|
echo "KO"
|
||||||
|
for error in $errors; do
|
||||||
|
echo " - $error"
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
done
|
@ -0,0 +1,75 @@
|
|||||||
|
#!/usr/bin/env zsh
|
||||||
|
# -------------------------------------------------------------------------------------------------
|
||||||
|
# Copyright (c) 2010-2011 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
|
||||||
|
# -------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
# Check an highlighter was given as argument.
|
||||||
|
[[ -n "$1" ]] || {
|
||||||
|
echo "You must provide the name of a valid highlighter as argument." >&2
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# Check the highlighter is valid.
|
||||||
|
[[ -f ${0:h:h}/highlighters/$1/$1-highlighter.zsh ]] || {
|
||||||
|
echo "Could not find highlighter '$1'." >&2
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# Check the highlighter has test data.
|
||||||
|
[[ -d ${0:h:h}/highlighters/$1/test-data ]] || {
|
||||||
|
echo "Highlighter '$1' has no test data." >&2
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# Load the main script.
|
||||||
|
. ${0:h:h}/zsh-syntax-highlighting.zsh
|
||||||
|
|
||||||
|
# Activate the highlighter.
|
||||||
|
ZSH_HIGHLIGHT_HIGHLIGHTERS=($1)
|
||||||
|
|
||||||
|
# Process each test data file in test data directory.
|
||||||
|
for data_file in ${0:h:h}/highlighters/$1/test-data/*; do
|
||||||
|
|
||||||
|
# Load the data and prepare checking it.
|
||||||
|
BUFFER=
|
||||||
|
echo -n "* ${data_file:t:r}: "
|
||||||
|
. $data_file
|
||||||
|
|
||||||
|
# Check the data declares $BUFFER.
|
||||||
|
if [[ ${#BUFFER} -eq 0 ]]; then
|
||||||
|
echo "KO\n - 'BUFFER' is not declared or blank."
|
||||||
|
else
|
||||||
|
|
||||||
|
# Measure the time taken by _zsh_highlight.
|
||||||
|
TIMEFMT="%*Es"
|
||||||
|
time ( BUFFER="$BUFFER" && _zsh_highlight)
|
||||||
|
|
||||||
|
fi
|
||||||
|
|
||||||
|
done
|
@ -0,0 +1 @@
|
|||||||
|
zsh-syntax-highlighting.zsh
|
@ -0,0 +1,218 @@
|
|||||||
|
#!/usr/bin/env zsh
|
||||||
|
# -------------------------------------------------------------------------------------------------
|
||||||
|
# Copyright (c) 2010-2011 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
|
||||||
|
# -------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
# -------------------------------------------------------------------------------------------------
|
||||||
|
# Core highlighting update system
|
||||||
|
# -------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
# Array declaring active highlighters names.
|
||||||
|
typeset -ga ZSH_HIGHLIGHT_HIGHLIGHTERS
|
||||||
|
|
||||||
|
# Update ZLE buffer syntax highlighting.
|
||||||
|
#
|
||||||
|
# Invokes each highlighter that needs updating.
|
||||||
|
# This function is supposed to be called whenever the ZLE state changes.
|
||||||
|
_zsh_highlight()
|
||||||
|
{
|
||||||
|
setopt localoptions nowarncreateglobal
|
||||||
|
|
||||||
|
# Store the previous command return code to restore it whatever happens.
|
||||||
|
local ret=$?
|
||||||
|
|
||||||
|
# Do not highlight if there are more than 300 chars in the buffer. It's most
|
||||||
|
# likely a pasted command or a huge list of files in that case..
|
||||||
|
[[ -n ${ZSH_HIGHLIGHT_MAXLENGTH:-} ]] && [[ $#BUFFER -gt $ZSH_HIGHLIGHT_MAXLENGTH ]] && return $ret
|
||||||
|
|
||||||
|
# Do not highlight if there are pending inputs (copy/paste).
|
||||||
|
[[ $PENDING -gt 0 ]] && return $ret
|
||||||
|
|
||||||
|
{
|
||||||
|
local -a selected_highlighters
|
||||||
|
local cache_place
|
||||||
|
|
||||||
|
# Select which highlighters in ZSH_HIGHLIGHT_HIGHLIGHTERS need to be invoked.
|
||||||
|
local highlighter; for highlighter in $ZSH_HIGHLIGHT_HIGHLIGHTERS; do
|
||||||
|
|
||||||
|
# If highlighter needs to be invoked
|
||||||
|
if "_zsh_highlight_${highlighter}_highlighter_predicate"; then
|
||||||
|
|
||||||
|
# Mark the highlighter as selected for update.
|
||||||
|
selected_highlighters+=($highlighter)
|
||||||
|
|
||||||
|
# Remove what was stored in its cache from region_highlight.
|
||||||
|
cache_place="_zsh_highlight_${highlighter}_highlighter_cache"
|
||||||
|
typeset -ga ${cache_place}
|
||||||
|
[[ ${#${(P)cache_place}} -gt 0 ]] && [[ ! -z ${region_highlight-} ]] && region_highlight=(${region_highlight:#(${(P~j.|.)cache_place})})
|
||||||
|
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
# Invoke each selected highlighter and store the result in its cache.
|
||||||
|
local -a region_highlight_copy
|
||||||
|
for highlighter in $selected_highlighters; do
|
||||||
|
cache_place="_zsh_highlight_${highlighter}_highlighter_cache"
|
||||||
|
region_highlight_copy=($region_highlight)
|
||||||
|
{
|
||||||
|
"_zsh_highlight_${highlighter}_highlighter"
|
||||||
|
} always {
|
||||||
|
[[ ! -z ${region_highlight-} ]] && : ${(PA)cache_place::=${region_highlight:#(${(~j.|.)region_highlight_copy})}}
|
||||||
|
}
|
||||||
|
done
|
||||||
|
|
||||||
|
} always {
|
||||||
|
_ZSH_HIGHLIGHT_PRIOR_BUFFER=$BUFFER
|
||||||
|
_ZSH_HIGHLIGHT_PRIOR_CURSOR=$CURSOR
|
||||||
|
return $ret
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# -------------------------------------------------------------------------------------------------
|
||||||
|
# API/utility functions for highlighters
|
||||||
|
# -------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
# Array used by highlighters to declare user overridable styles.
|
||||||
|
typeset -gA ZSH_HIGHLIGHT_STYLES
|
||||||
|
|
||||||
|
# Whether the command line buffer has been modified or not.
|
||||||
|
#
|
||||||
|
# Returns 0 if the buffer has changed since _zsh_highlight was last called.
|
||||||
|
_zsh_highlight_buffer_modified()
|
||||||
|
{
|
||||||
|
[[ ${_ZSH_HIGHLIGHT_PRIOR_BUFFER:-} != $BUFFER ]]
|
||||||
|
}
|
||||||
|
|
||||||
|
# Whether the cursor has moved or not.
|
||||||
|
#
|
||||||
|
# Returns 0 if the cursor has moved since _zsh_highlight was last called.
|
||||||
|
_zsh_highlight_cursor_moved()
|
||||||
|
{
|
||||||
|
[[ -n $CURSOR ]] && [[ -n ${_ZSH_HIGHLIGHT_PRIOR_CURSOR-} ]] && (($_ZSH_HIGHLIGHT_PRIOR_CURSOR != $CURSOR))
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# -------------------------------------------------------------------------------------------------
|
||||||
|
# Setup functions
|
||||||
|
# -------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
# Rebind all ZLE widgets to make them invoke _zsh_highlights.
|
||||||
|
_zsh_highlight_bind_widgets()
|
||||||
|
{
|
||||||
|
# Load ZSH module zsh/zleparameter, needed to override user defined widgets.
|
||||||
|
zmodload zsh/zleparameter 2>/dev/null || {
|
||||||
|
echo 'zsh-syntax-highlighting: failed loading zsh/zleparameter.' >&2
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# Override ZLE widgets to make them invoke _zsh_highlight.
|
||||||
|
local cur_widget
|
||||||
|
for cur_widget in ${${(f)"$(builtin zle -la)"}:#(.*|_*|orig-*|run-help|which-command|beep)}; do
|
||||||
|
case $widgets[$cur_widget] in
|
||||||
|
|
||||||
|
# Already rebound event: do nothing.
|
||||||
|
user:$cur_widget|user:_zsh_highlight_widget_*);;
|
||||||
|
|
||||||
|
# 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 }; \
|
||||||
|
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 }; \
|
||||||
|
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 }; \
|
||||||
|
zle -N $cur_widget _zsh_highlight_widget_$cur_widget";;
|
||||||
|
|
||||||
|
# Default: unhandled case.
|
||||||
|
*) echo "zsh-syntax-highlighting: unhandled ZLE widget '$cur_widget'" >&2 ;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
# Load highlighters from directory.
|
||||||
|
#
|
||||||
|
# Arguments:
|
||||||
|
# 1) Path to the highlighters directory.
|
||||||
|
_zsh_highlight_load_highlighters()
|
||||||
|
{
|
||||||
|
# Check the directory exists.
|
||||||
|
[[ -d "$1" ]] || {
|
||||||
|
echo "zsh-syntax-highlighting: highlighters directory '$1' not found." >&2
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# Load highlighters from highlighters directory and check they define required functions.
|
||||||
|
local highlighter highlighter_dir
|
||||||
|
for highlighter_dir ($1/*/); do
|
||||||
|
highlighter="${highlighter_dir:t}"
|
||||||
|
[[ -f "$highlighter_dir/${highlighter}-highlighter.zsh" ]] && {
|
||||||
|
. "$highlighter_dir/${highlighter}-highlighter.zsh"
|
||||||
|
type "_zsh_highlight_${highlighter}_highlighter" &> /dev/null &&
|
||||||
|
type "_zsh_highlight_${highlighter}_highlighter_predicate" &> /dev/null || {
|
||||||
|
echo "zsh-syntax-highlighting: '${highlighter}' highlighter should define both required functions '_zsh_highlight_${highlighter}_highlighter' and '_zsh_highlight_${highlighter}_highlighter_predicate' in '${highlighter_dir}/${highlighter}-highlighter.zsh'." >&2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# -------------------------------------------------------------------------------------------------
|
||||||
|
# Setup
|
||||||
|
# -------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
# Try binding widgets.
|
||||||
|
_zsh_highlight_bind_widgets || {
|
||||||
|
echo 'zsh-syntax-highlighting: failed binding ZLE widgets, exiting.' >&2
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# Resolve highlighters directory location.
|
||||||
|
_zsh_highlight_load_highlighters "${ZSH_HIGHLIGHT_HIGHLIGHTERS_DIR:-${0:h}/highlighters}" || {
|
||||||
|
echo 'zsh-syntax-highlighting: failed loading highlighters, exiting.' >&2
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# Reset scratch variables when commandline is done.
|
||||||
|
_zsh_highlight_preexec_hook()
|
||||||
|
{
|
||||||
|
_ZSH_HIGHLIGHT_PRIOR_BUFFER=
|
||||||
|
_ZSH_HIGHLIGHT_PRIOR_CURSOR=
|
||||||
|
}
|
||||||
|
autoload -U add-zsh-hook
|
||||||
|
add-zsh-hook preexec _zsh_highlight_preexec_hook 2>/dev/null || {
|
||||||
|
echo 'zsh-syntax-highlighting: failed loading add-zsh-hook.' >&2
|
||||||
|
}
|
||||||
|
|
||||||
|
# Initialize the array of active highlighters if needed.
|
||||||
|
[[ $#ZSH_HIGHLIGHT_HIGHLIGHTERS -eq 0 ]] && ZSH_HIGHLIGHT_HIGHLIGHTERS=(main) || true
|
@ -0,0 +1,33 @@
|
|||||||
|
if [ -f $HOME/.zsh/zsh.conf ]
|
||||||
|
then
|
||||||
|
source $HOME/.zsh/zsh.conf
|
||||||
|
else
|
||||||
|
echo 'CONFIGURATION NOT SET!\n Copy zsh.conf from the example_configs directory and set up your preferences!\n Setting basic parameters only!' >&2
|
||||||
|
source $HOME/.zsh/history
|
||||||
|
source $HOME/.zsh/interactive
|
||||||
|
source $HOME/.zsh/exports
|
||||||
|
source $HOME/.zsh/bindkeys
|
||||||
|
source $HOME/.zsh/completion
|
||||||
|
source $HOME/.zsh/setopt
|
||||||
|
PROMPT="UNCONFIGURED% "
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
source $HOME/.zsh/history
|
||||||
|
source $HOME/.zsh/alias
|
||||||
|
source $HOME/.zsh/interactive
|
||||||
|
source $HOME/.zsh/exports
|
||||||
|
source $HOME/.zsh/bindkeys
|
||||||
|
source $HOME/.zsh/completion
|
||||||
|
source $HOME/.zsh/setopt
|
||||||
|
if [ $SYNTAX_HIGHLIGHT ]
|
||||||
|
then
|
||||||
|
source $HOME/.zsh/zsh-syntax-highlight/zsh-syntax-highlighting.zsh
|
||||||
|
fi
|
||||||
|
source $HOME/.zsh/prompt
|
||||||
|
if [ -f $HOME/.zsh/custom ]
|
||||||
|
then
|
||||||
|
source $HOME/.zsh/custom
|
||||||
|
fi
|
||||||
|
|
||||||
|
PATH=$PATH:$HOME/bin:/opt/java/current/bin
|
||||||
|
|
Loading…
Reference in new issue