1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | PROFILE_CONFIG=false
[[ $PROFILE_CONFIG == true ]] && zmodload zsh/zprof
source "${ZDOTDIR}/01-init.zsh"
source "${ZDOTDIR}/zsh-defer/zsh-defer.plugin.zsh"
source "${ZDOTDIR}/03-exports.zsh"
source "${ZDOTDIR}/04-prompt.zsh"
source "${ZDOTDIR}/05-cmds.zsh"
zsh-defer source "${ZDOTDIR}/12-completion.zsh"
zsh-defer source "${ZDOTDIR}/13-bindkeys.zsh"
zsh-defer source "${ZDOTDIR}/70-forgit.zsh"
zsh-defer source "${ZDOTDIR}/81-completion_gen.zsh"
zsh-defer source "${ZDOTDIR}/96-fzf.zsh"
zsh-defer source "${ZDOTDIR}/98-syntax.zsh"
[[ ${PROFILE_CONFIG} == true ]] && zprof
|
x
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 | # autoload wrapper - use this one instead of autoload directly
# We need to define this function as early as this, because autoloading
# 'is-at-least()' needs it.
function zrcautoload() {
emulate -L zsh
setopt extended_glob
local fdir ffile
local -i ffound
ffile=$1
(( ffound = 0 ))
for fdir in ${fpath} ; do
[[ -e ${fdir}/${ffile} ]] && (( ffound = 1 ))
done
(( ffound == 0 )) && return 1
autoload -U ${ffile} || return 1
return 0
}
# Speeds up load time
DISABLE_UPDATE_PROMPT=true
# Perform compinit only once a day.
autoload -Uz compinit
setopt EXTENDEDGLOB
for dump in ${HOME}/.zcompdump(#qN.m1); do
compinit
if [[ -s "${dump}" && (! -s "${dump}.zwc" || "${dump}" -nt "${dump}.zwc") ]]; then
zcompile "${dump}"
fi
done
unsetopt EXTENDEDGLOB
compinit -C
zrcautoload colors && colors
eval $(keychain --eval --quiet id_rsa)
zle_highlight+=(suffix:fg=blue)
unset MAILCHECK
{
stty eof 2> /dev/null # stty eof ''
stty ixany
stty ixoff -ixon # Disable XON/XOFF flow control; this is required to make C-s work in Vim.
} &!
function stty_setup(){
stty time 0 2> /dev/null
stty min 0 2> /dev/null
stty line 6 2> /dev/null
stty speed 38400 &> /dev/null
}
[[ $- =~ i ]] && stty_setup &!
[[ -f ~/.config/dircolors/.dircolors ]] && eval $(dircolors ~/.config/dircolors/.dircolors)
ulimit -c 0 # No core dumps for now
setopt append_history # this is default, but set for share_history
setopt share_history # import new commands from the history file also in other zsh-session
setopt extended_history # save each command's beginning timestamp and the duration to the history file
setopt histignorealldups # remove command lines from the history list when the first character on the line is a space
setopt hist_expire_dups_first # when trimming history, lose oldest duplicates first
setopt hist_ignore_dups # ignore duplication command history list
setopt hist_verify # don't execute, just expand history
setopt hist_ignore_space # reduce whitespace in history
setopt inc_append_history # add comamnds as they are typed, don't wait until shell exit
# remove command lines from the history list when the first character on the
# line is a space
setopt histignorespace
# if a command is issued that can't be executed as a normal command, and the
# command is the name of a directory, perform the cd command to that directory.
setopt auto_cd
# in order to use #, ~ and ^ for filename generation grep word
# *~(*.gz|*.bz|*.bz2|*.zip|*.Z) -> searches for word not in compressed files
# don't forget to quote '^', '~' and '#'!
setopt extended_glob # ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^^ ^ ^ ^ ^
setopt longlistjobs # display PID when suspending processes as well
setopt nonomatch # try to avoid the 'zsh: no matches found...'
setopt notify # report the status of backgrounds jobs immediately
setopt hash_list_all # whenever a command completion is attempted, make sure the entire command path is hashed first.
setopt completeinword # not just at the end
setopt nohup # don't send SIGHUP to background processes when the shell exits.
setopt auto_pushd # make cd push the old directory onto the directory stack.
setopt pushdminus # pushd -N goes to Nth dir in stack
setopt pushdsilent # do not print dirstack after each cd/pushd
setopt pushdtohome #pushd with no args pushes to home
setopt pushd_ignore_dups # don't push the same dir twice.
setopt nobeep # get rid of beeps
setopt noglobdots # * shouldn't match dotfiles. ever.
setopt noshwordsplit # use zsh style word splitting
setopt noflowcontrol # no c-s/c-q output freezing
setopt c_bases # print $(( [#16] 0xff ))
setopt prompt_subst # set the prompt
# make sure to use right prompt only when not running a command
setopt transient_rprompt # only show the rprompt on the current prompt
setopt interactivecomments # allow interactive comments
setopt always_to_end # When completing from the middle of a word, move the cursor to the end of the word
setopt extendedglob # enable extended globbing
setopt interactivecomments # allow interactive comments after '#' in command line
# ~ substitution and tab completion after a = (for --x=filename args)
setopt magicequalsubst
# setopt glob_star_short # */** -> **
# watch for everyone but me and root
watch=(notme root)
# automatically remove duplicates from these arrays
typeset -U path cdpath fpath manpath
#fpath=(
# "${ZDOTDIR}/zsh-completions/src"
# "~/.zsh/compdef"
# "${ZDOTDIR}/zle"
# "${fpath}"
#)
zrcautoload zmv # who needs mmv or rename?
zrcautoload history-search-end
zrcautoload split-shell-arguments
zrcautoload zed # use ZLE editor to edit a file or function
for mod in complist deltochar mathfunc ; do
zmodload -i zsh/${mod} 2>/dev/null || print "Notice: no ${mod} available :("
done
# autoload zsh modules when they are referenced
zmodload -a zsh/stat zstat
zmodload -a zsh/zpty zpty
zmodload -ap zsh/mapfile mapfile
# Use hard limits, except for a smaller stack and no core dumps
unlimit
limit stack 8192
limit core 0 # important for a live-cd-system
limit -s
# Keeps track of the last used working directory and automatically jumps
# into it for new shells.
export ZSH=~/.zsh
|
x
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 | source "${ZDOTDIR}/03-helpers.zsh"
source "${ZDOTDIR}/03-xdg_vars.zsh"
path_dirs=(
/usr/bin
${HOME}/bin
{/usr/local,}/{s,}bin
/usr/bin/{site,vendor,core}_perl
/opt/go/bin
/home/neg/.cargo/bin
)
whence ruby >/dev/null && \
path_dirs+=$($(whence ruby) -e 'puts Gem.user_dir')/bin
export PATH=${(j_:_)path_dirs}
unset SSH_ASKPASS
export VIDIR_EDITOR_ARGS='-c :set nolist | :set ft=vidir-ls'
export AURDEST=$(readlink -f "${HOME}/tmp/pacaur")
export PYTHONIOENCODING='utf-8'
export GREP_COLOR='37;45'
export GREP_COLORS='ms=0;32:mc=1;33:sl=:cx=:fn=1;32:ln=1;36:bn=36:se=1;30'
for q in nvim vim vi;
{ [[ -n ${commands}[(I)${q}] ]] \
&& export EDITOR=${q}; break }
if which nvimpager >/dev/null; then
export PAGER="nvimpager"
elif hash slit > /dev/null; then
export PAGER="slit"
else
for q in nvim vim vi;
{ [[ -n ${commands}[(I)${q}] ]] \
&& export VISUAL=${q}; break }
fi
alias less=${PAGER}
alias zless=${PAGER}
export MANPAGER="/bin/sh -c \"col -b | nvim -c 'set ft=man ts=8 nomod nolist noma' -\""
export INPUTRC="${XDG_CONFIG_HOME}/inputrc"
export BROWSER="firefox"
export VAGRANT_HOME="/zero/vagrant"
export PERLBREW_ROOT=${HOME}/.perl5
export LESSCHARSET=UTF-8
export LESS_TERMCAP_mb="$(tput bold; tput setaf 2)" # begin blinking
export LESS_TERMCAP_md="$(tput bold)" # begin bold
export LESS_TERMCAP_me="$(tput sgr0)" # end mode
export LESS_TERMCAP_so="$(tput bold; tput setaf 6)" # begin standout - info box
export LESS_TERMCAP_se="$(tput sgr0)" # end standout
export LESS_TERMCAP_us="$(tput bold; tput setaf 2)" # begin underline
export LESS_TERMCAP_ue="$(tput sgr0)" # end underline
export TEXINPUTS=".:${XDG_DATA_HOME}/texmf//:"
export HISTFILE=${ZDOTDIR}/zsh_history
export SAVEHIST=100000 # useful for setopt append_history
export HISTSIZE=$(( $SAVEHIST * 1.10 ))
export HISTIGNORE="&:ls:[bf]g:exit:reset:clear:cd*:gs:gd"
export HISTCONTROL=ignoreboth:erasedups # ignoreboth (= ignoredups + ignorespace)
local -a timefmt_=(
"$(zwrap "$(zfwrap "%J")")"
"$(zwrap "%U")"
"$(zwrap "user %S")"
"$(zwrap "system %P")"
"$(zwrap "cpu %*E total")"
"$(zwrap "-||-")"
"$(zwrap "Mem: %M kb max")"
)
export TIMEFMT="${timefmt_[@]}"
export COLORTERM="yes"
export LS_COLORS
export WORDCHARS='*?_-.[]~&;!#$%^(){}<>~` '
export MPV_HOME="${HOME}/.config/mpv"
export MANWIDTH=${MANWIDTH:-80}
export GOPATH=/opt/go
export GOMAXPROCS=8
export KEYTIMEOUT=5 # allow to use ,<key> more fast
export ESCDELAY=1
export OSSLIBDIR=/usr/lib/oss
export JAVA_FONTS=/usr/share/fonts/TTF
export _JAVA_AWT_WM_NONREPARENTING=1
export _JAVA_OPTIONS='-Dawt.useSystemAAFontSettings=on -Dswing.aatext=true -Dswing.defaultlaf=com.sun.java.swing.plaf.gtk.GTKLookAndFeel -Dswing.crossplatformlaf=com.sun.java.swing.plaf.gtk.GTKLookAndFeel'
_SILENT_JAVA_OPTIONS="${_JAVA_OPTIONS}"
(( 0 != 0 )) && {
if which drip > /dev/null 2>&1; then
export DRIP_SHUTDOWN=30
export JAVACMD=$(which drip)
fi
}
export PULSE_LATENCY_MSEC=60
export STEAM_RUNTIME=1
export AUTOPAIR_INHIBIT_INIT=1
(){
local _home="/mnt/home"
local _dev="/one/dev"
hash -d q=${_dev}
hash -d d="${_home}/doc"
hash -d torrent="${_home}/torrent"
hash -d v="${_home}/vid/new"
hash -d {z,s}="${_dev}/src"
hash -d p='/home/neg/pic'
}
export QT_QPA_PLATFORMTHEME="qt5ct"
|
x
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | export XDG_CONFIG_HOME="${HOME}/.config"
export XDG_DATA_HOME="${HOME}/.local/share"
export XDG_CACHE_HOME="${HOME}/.cache"
export XDG_DOWNLOAD_DIR="${HOME}/dw"
export XDG_MUSIC_DIR="${HOME}/music"
export XDG_DESKTOP_DIR="${HOME}/.local/desktop"
export XDG_TEMPLATES_DIR="${HOME}/1st_level/templates"
export XDG_DOCUMENTS_DIR="${HOME}/doc/"
export XDG_PICTURES_DIR="${HOME}/pic"
export XDG_VIDEOS_DIR="${HOME}/vid"
export XDG_PUBLICSHARE_DIR="${HOME}/1st_level/upload/share"
export ZSHDIR="${ZDOTDIR}"
export BIN_HOME="${HOME}/bin"
export SCRIPT_HOME="${BIN_HOME}/scripts"
export SXHKD_FIFO="/tmp/sxhkd_fifo"
export SXHKD_SHELL="zsh"
|
x
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 | if [[ -z $GIT_PROMPT_ORDER ]]; then
GIT_PROMPT_ORDER=(
"prefix"
"branch"
"behind"
"ahead"
"separator"
"staged"
"changed"
"conflicts"
"untracked"
"clean"
"suffix"
)
fi
declare -A GIT_PROMPT_SYMBOLS
lhs="⟬" rhs="⟭"
if [[ -z $GIT_PROMPT_SYMBOLS ]]; then
declare -A GIT_PROMPT_SYMBOLS
GIT_PROMPT_SYMBOLS=(
"prefix" "%F{4}${lhs}%f"
"branch" "%F{7}"
"behind" "%F{25}%{←%G%}"
"ahead" "%F{25}%{→%G%}"
"separator" "%F{206}|%f"
"staged" "%F{117}%{♦%G%}"
"changed" "%F{226}%{◊%G%}"
"conflicts" "%F{9}%{≠%G%}"
"untracked" "%F{1}%{…%G%}"
"clean" "%F{10}%B%{✓%G%}%b"
"suffix" "%F{4}${rhs}%f%{$reset_color%}"
)
fi
# Remove right margin from $RPROMPT. In theory, setting ZLE_RPROMPT_INDENT
# appropriately should be enough, but in practice results vary:
# https://superuser.com/q/655607
: ${GIT_PROMPT_INDENT_HACK:=1}
declare -A GIT_STATUS_MAP
GIT_STATUS_MAP=(
' M' 'changed' # not updated, work tree changed since index
' D' 'changed' # not updated, deleted in work tree
' T' 'changed' # type changed in work tree, not staged
'M ' 'staged' # updated in index, index and work tree matches
'MM' 'changed' # updated in index, work tree changed since index
'MD' 'changed' # updated in index, deleted in work tree
'MT' 'changed' # updated in index, type changed in work tree
'A ' 'staged' # added to index, index and work tree matches
'AM' 'changed' # added to index, work tree changed since index
'AD' 'changed' # added to index, deleted in work tree
'AT' 'changed' # added to index, type changed in work tree
'D ' 'staged' # deleted from index
'DM' 'changed' # deleted from index
'R ' 'staged' # renamed in index, index and work tree matches
'RM' 'changed' # renamed in index, work tree changed since index
'RD' 'changed' # renamed in index, deleted in work tree
'C ' 'staged' # copied in index, index and work tree matches
'CM' 'changed' # copied in index, work tree changed since index
'CD' 'changed' # copied in index, deleted in work tree
'T ' 'staged' # type changed in index, index and work tree matches
'TM' 'changed' # type changed in index and matches type in work tree, content differs
'TD' 'changed' # type changed in index, deleted in work tree
'TT' 'changed' # type changed in index and differs from type in work tree
'DD' 'conflicts' # unmerged, both deleted
'AU' 'conflicts' # unmerged, added by us
'UD' 'conflicts' # unmerged, deleted by them
'UA' 'conflicts' # unmerged, added by them
'DU' 'conflicts' # unmerged, deleted by us
'AA' 'conflicts' # unmerged, both added
'UU' 'conflicts' # unmerged, both modified
'??' 'untracked' # untracked
'!!' 'ignored' # ignored
)
GIT_PROMPT_FIFO_DIR="${HOME}/tmp/zsh-git-prompt"
if [[ $GIT_PROMPT_INDENT_HACK -eq 1 ]]; then
if [[ $TMUX_PANE ]]; then
export ZLE_RPROMPT_INDENT=0
else
export ZLE_RPROMPT_INDENT=1
fi
fi
function git_get_status() {
local status_string map_status chunk chunk_index mapped_status
local -a status_chunks
local -A git_flags git_strings git_numbers
status_string="$(git status --branch -u --porcelain -z 2> /dev/null)"
if [[ $? -ne 0 ]]; then
git_flags=(
"in_repo" 0
)
typeset -p git_flags git_strings git_numbers
return
fi
for map_status in $GIT_STATUS_MAP; do
git_numbers[$map_status]=0
done
status_chunks=(${(0)status_string})
chunk_index=1
while [[ chunk_index -le ${#status_chunks} ]]; do
chunk="${status_chunks[$chunk_index]}"
if [[ "${chunk:0:2}" == '##' ]]; then
git_parse_status_header "${chunk:2}"
git_strings[branch]="$RETURN_BRANCH"
git_numbers[ahead]=$RETURN_AHEAD
git_numbers[behind]=$RETURN_BEHIND
else
mapped_status=${GIT_STATUS_MAP[${chunk:0:2}]}
git_numbers[$mapped_status]=$((git_numbers[$mapped_status] + 1))
fi
if [[ "${chunk:0:2}" == R* || "${chunk:0:2}" == C* ]]; then
chunk_index=$((chunk_index + 2))
else
chunk_index=$((chunk_index + 1))
fi
done
git_flags[in_repo]=1
git_flags[clean]=0
if [[ \
${git_numbers[staged]} -eq 0
&& ${git_numbers[changed]} -eq 0
&& ${git_numbers[conflicts]} -eq 0
&& ${git_numbers[untracked]} -eq 0
]] then
git_flags[clean]=1
fi
typeset -p git_flags git_strings git_numbers
}
function git_parse_status_header() {
local branches divergence div
typeset -g RETURN_AHEAD RETURN_BEHIND RETURN_BRANCH
RETURN_AHEAD=0
RETURN_BEHIND=0
if [[ "$1" == *'Initial commit on '* ]]; then
RETURN_BRANCH="${1/#*'Initial commit on '/}"
return
fi
if [[ "$1" == *'No commits yet on '* ]]; then
RETURN_BRANCH="${1/#*'No commits yet on '/}"
return
fi
if [[ "$1" == *'no branch'* ]]; then
git_get_tag_or_hash
RETURN_BRANCH="$RETURN_TAG_OR_HASH"
return
fi
if [[ "$1" == *'...'* ]]; then
# local and remote branch info
branches=(${(s:...:)1})
RETURN_BRANCH="${branches[1]# }"
if [[ $#branches -ne 1 ]]; then
# ahead or behind
divergence="${(M)branches[2]%\[*\]}"
divergence="${divergence#\[}"
divergence="${divergence%\]}"
for div in ${(s:, :)divergence}; do
if [[ "$div" == 'ahead '* ]]; then
RETURN_AHEAD="${div#ahead }"
elif [[ "$div" == 'behind '* ]]; then
RETURN_BEHIND="${div#behind }"
fi
done
fi
return
fi
RETURN_BRANCH="${1# }"
}
function git_get_tag_or_hash() {
local log_string
local refs ref
local ret_hash ret_tag
typeset -g RETURN_TAG_OR_HASH
log_string="$(git log -1 --decorate=full --format="%h%d" 2> /dev/null)"
if [[ "$log_string" == *' ('*')' ]]; then
ret_hash="${log_string%% (*)}"
refs="${(M)log_string%% (*)}"
refs="${refs# \(}"
refs="${refs%\)}"
for ref in ${(s:, :)refs}; do
if [[ "$ref" == 'refs/tags/'* ]]; then # git 1.7.x
ret_tag="${ref#refs/tags/}"
elif [[ "$ref" == 'tag: refs/tags/'* ]]; then # git 2.1.x
ret_tag="${ref#tag: refs/tags/}"
fi
if [[ "$ret_tag" != "" ]]; then
RETURN_TAG_OR_HASH="tags/$ret_tag"
return
fi
done
RETURN_TAG_OR_HASH="$ret_hash"
fi
}
function git_prompt_completed_callback() {
local symbol line k buffer=""
while read -t 0 -r -u $GIT_PROMPT_DESCRIPTOR line; do
eval $line
done
if [[ ${git_flags[in_repo]} -eq 1 ]]; then
for k in $GIT_PROMPT_ORDER; do
symbol="${GIT_PROMPT_SYMBOLS[$k]}"
if [[ $GIT_PROMPT_INDENT_HACK -eq 1 ]]; then
if [[ -z $TMUX_PANE ]]; then
if [[ $k == suffix ]]; then
symbol="%{$symbol%}"
fi
fi
fi
if [[ ${git_strings[$k]} != "" ]] then
buffer+="$symbol${git_strings[$k]}"
elif [[ ${git_numbers[$k]} != "" ]] then
if [[ ${git_numbers[$k]} != 0 ]] then
buffer+="$symbol${git_numbers[$k]}"
fi
elif [[ ${git_flags[$k]} != "" ]]; then
if [[ ${git_flags[$k]} -eq 1 ]] then
buffer+="$symbol"
fi
else
buffer+="$symbol"
fi
done
fi
RPROMPT=$buffer
zle && zle reset-prompt
}
function git_prompt_bg() {
git_get_status >&$GIT_PROMPT_DESCRIPTOR
kill -s USR1 $$
}
function git_prompt_hook() {
if [[ $GIT_PROMPT_BG_PID != 0 ]]; then
kill -s HUP $GIT_PROMPT_BG_PID > /dev/null 2>&1
fi
git_prompt_bg &!
GIT_PROMPT_BG_PID=$!
}
function git_prompt_init() {
typeset -g GIT_PROMPT_BG_PID GIT_PROMPT_DESCRIPTOR
GIT_PROMPT_BG_PID=0
local fifo="$GIT_PROMPT_FIFO_DIR/$$.fifo"
mkdir -m 700 -p "$GIT_PROMPT_FIFO_DIR"
mkfifo -m 600 $fifo
exec {GIT_PROMPT_DESCRIPTOR}<>$fifo
rm -f $fifo
}
function TRAPUSR1() {
git_prompt_completed_callback
GIT_PROMPT_BG_PID=0
}
autoload -Uz add-zsh-hook
add-zsh-hook precmd git_prompt_hook
git_prompt_init
export PROMPT_FST="❯"
export PROMPT_SND=">"
local tilda_color='2'
local prompt_color='4'
local error_color='4'
typeset -A possible_lhs=(
['0']="%F{25}⟬%F{4}<"
['1']="❬"
['2']="❲"
['3']="%F{25}⟬%F{4}<"
['4']="❬"
['5']="❲"
)
typeset -A possible_rhs=(
['0']="⧔"
['1']="❭"
['2']="❳"
['3']=""
['4']="❭"
['5']="❳"
)
function precmd {
export tilda_color
export prompt_color
export error_color
export PROMPT_LHS="%F{${prompt_color}}⟬"
export PROMPT_RHS=""
export MAIN_COLOR="%(?.%F{${prompt_color}}.%F{${error_color}})"
export TILDA_COLOR="%(?.%F{${tilda_color}}.%F{${prompt_color}})"
export PS1="$(${ZDOTDIR}/neg-prompt)"
}
SPROMPT="%F{7}Correct: %F{4}%R%f %F{7}-> %F{2}%r%F{7} [nyae]? %f"
PS2="%F{5}❭ %f"
PS3='?# '
PS4='+%N:%i:%_> '
|
x
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 | chpwd() {
if [[ -x ${BIN_HOME}/Z ]]; then
[[ "${PWD}" -ef "${HOME}" ]] || Z -a "${PWD}"
fi
hash setup_prompt 2> /dev/null && setup_prompt
}
local readonly use_cope_path=false
if [[ ${use_cope_path} == true ]]; then
if [[ -x $(which cope_path 2> /dev/null) ]]; then
# to prevent slow cope_path evaluation
local copepath=$(cope_path)
for i in "${copepath}"/*; alias $(basename ${i})=\"$i\"
alias df="${copepath}/df -hT"
else
alias df="df -hT"
fi
else
local copepath=${SCRIPT_HOME}/Cope
for i in "${copepath}"/*; alias $(basename ${i})=\"$i\"
alias df="${copepath}/df -hT"
fi
unset copepath
zc(){
autoload -U zrecompile
for z in ${ZDOTDIR}/*.zsh ${ZDOTDIR}/.zshrc; do
zrecompile -p ${z}
print $(zpref) $(zfwrap "${z}")
rm -fv "${z}.zwc.old"
done
for f in ${zcompdumpfile};
zrecompile -p "${f}" && \
rm -f "${f}.zwc.old"
source ${ZDOTDIR}/.zshrc
}
# grep for running process, like: 'any vime
any() {
emulate -L zsh
unsetopt KSH_ARRAYS
if [[ -z "$1" ]] ; then
if [[ -x $(which fzf-tmux) ]]; then
ps xauwww | fzf-tmux
fi
else
ps xauwww | grep --color=auto -i "[${1[1]}]${1[2,-1]}"
fi
}
imv() {
local src dst
for src; do
[[ -e ${src} ]] || { print -u2 "${src} does not exist"; continue }
dst=${src}
vared dst
[[ ${src} != ${dst} ]] && mkdir -p ${dst:h} && mv -n ${src} ${dst}
done
}
fasd_cache="${XDG_CACHE_HOME}/fasd-init-cache"
if [ "$(command -v fasd)" -nt "${fasd_cache}" -o ! -s "${fasd_cache}" ]; then
fasd --init auto >| "${fasd_cache}"
fi
source "${fasd_cache}"
unset fasd_cache
dropcache() { sync && command sudo /bin/zsh -c 'echo 3 > /proc/sys/vm/drop_caches' }
lastfm_scrobbler_toggle(){
local is_run="active (running)"
local use_mpdscribble=false
if [[ use_mpdscribble == true ]]; then
if [[ "$(systemctl --user status mpdscribble.service|grep -o "${is_run}")" != "" ]]; then
systemctl --user stop mpdscribble
=mpdscribble --conf ${XDG_CONFIG_HOME}/mpdscribble/hextrick.conf --no-daemon &!
else
pkill mpdscribble
systemctl --user start mpdscribble.service
fi
builtin printf "$(zpref) $(zfwrap "$(any mpdscribble | awk '{print substr($0, index($0,$11))}'|
sed "s|${HOME}|$fg[green]~|;s|/|$fg[blue]&$fg[white]|g")")\n"
else
if [[ "$(systemctl --user status mpdas.service|grep -o "${is_run}")" != "" ]]; then
systemctl --user stop mpdas.service
=mpdas -c ${XDG_CONFIG_HOME}/mpdas/hextrick.rc 2&> /dev/null &!
else
pkill mpdas
systemctl --user start mpdas.service
fi
builtin printf "$(zpref) $(zfwrap "$(any mpdas | awk '{print substr($0, index($0,$11))}'|
sed "s|${HOME}|$fg[green]~|;s|/|$fg[blue]&$fg[white]|g")")\n"
fi
unset is_run use_mpdscribble
}
pid2xid(){ wmctrl -lp | awk "\$3 == $(pgrep $1) {print \$1}" }
ql(){
if [[ $1 != "" ]]; then
local file=$(resolve_file "$1")
local upload_dir=${HOME}/1st_level/upload/
cp "${file}" "${upload_dir}" && \
builtin printf "$(zfwrap ${file})\n"
xsel -o <<< "${upload_dir}/$(basename ${file})"
fi
}
which() {
if [[ $# > 0 ]]; then
if [[ -x /usr/bin/ccat ]]; then
builtin which "$@" | ccat
else
builtin which "$@"
fi
fi
}
py23switch(){
python_path="$(which python)"
if [[ $(basename $(readlink /usr/sbin/python)) == python3 ]]; then
echo ':: set python (3 to 2) ::'
sudo ln -fs /usr/sbin/python2 /usr/sbin/python && \
l ${python_path}
elif
[[ $(basename $(readlink /usr/sbin/python)) == python2 ]]; then
echo ':: set python (2 to 3) ::'
sudo ln -fs /usr/sbin/python3 /usr/sbin/python && \
l ${python_path}
fi
}
local noglob_list=(
fc find {,s,l}ftp history locate rake rsync scp
eix {z,m}mv wget clive{,scan} youtube-{dl,viewer}
translate links{,2} lynx you-get bower pip task
)
local rlwrap_list=(
bigloo clisp irb guile bb
)
local sudo_list=({u,}mount ch{mod,own} modprobe i7z aircrack-ng)
local user_commands=(
list-units is-active status show help list-unit-files
is-enabled list-jobs show-environment cat
)
local systemctl_sudo_commands=(
start stop reload restart try-restart isolate kill
reset-failed enable disable reenable preset mask unmask
link load cancel set-environment unset-environment
edit
)
local logind_sudo_list=(
reboot halt poweroff
)
local nocorrect_commands=(
ebuild gist heroku hpodder man mkdir mv mysql sudo
)
for c in ${user_commands}; do; alias sc-${c}="systemctl ${c}"; done
for c in ${systemctl_sudo_commands}; do; alias sc-${c}="sudo systemctl ${c}"; done
for i in ${sudo_list[@]}; alias "${i}=sudo ${i}";
for i in ${noglob_list[@]}; alias "${i}=noglob ${i}";
for i in ${rlwrap_list[@]}; alias "${i}=rlwrap ${i}";
for i in ${nocorrect_list[@]}; alias "${i}=nocorrect ${i}";
[[ -x /usr/bin/systemctl ]] && sysctl_pref="systemctl"
for i in ${logind_sudo_list[@]}; alias "${i}=sudo ${sysctl_pref} ${i}"
unset noglob_list rlwrap_list sudo_list sys_sudo_list
if [[ ! -x "${BIN_HOME}/l" ]] && [[ ! -x $(which l) ]]; then
alias l="ls -aChkopl --group-directories-first --color=auto"
else
alias l='l -g'
fi
alias ls="ls --color=auto" # do we have GNU ls with color-support?
alias s="sudo"
alias x='xargs'
alias e="mimeo"
alias u='umount'
alias magnet2torrent="aria2c -q --bt-metadata-only --bt-save-metadata"
mp(){
for i; vid_fancy_print "${i}"
mpv --input-ipc-server=/tmp/mpvsocket --vo=gpu "$@" > ${HOME}/tmp/mpv.log
}
alias mpa="mpv --input-ipc-server=/tmp/mpvsocket --vo=gpu "$@" -mute > ${HOME}/tmp/mpv.log"
alias mpA="mpv --input-ipc-server=/tmp/mpvsocket --vo=gpu "$@" -fs -ao null > ${HOME}/tmp/mpv.log"
alias mpi="mpv --input-ipc-server=/tmp/mpvsocket --vo=gpu --interpolation=yes --tscale='oversample' --video-sync='display-resample' "$@" > ${HOME}/tmp/mpv.log"
alias love="mpc sendmessage mpdas love"
alias unlove="mpc sendmessage mpdas unlove"
alias grep="grep --color=auto"
alias rg="rg --colors 'match:fg:magenta' --colors 'line:fg:cyan'"
alias mutt="dtach -A ${HOME}/1st_level/mutt.session neomutt"
alias pstop='ps -eo cmd,fname,pid,pcpu,time --sort=-pcpu | head -n 11 && echo && ps -eo cmd,fname,pid,pmem,rss --sort=-rss | head -n 9'
alias '?=bc -l <<<'
??() { curl -s cheat.sh/$@ }
alias {z,m}mv="noglob zmv -Wn"
alias mv="mv -i"
alias mk="mkdir -p"
alias rd="rmdir"
alias acpi="acpi -V"
alias se="patool extract"
alias pk="patool create"
alias url-quote='autoload -U url-quote-magic ; zle -N self-insert url-quote-magic'
if hash git 2>/dev/null; then
alias gs='git status --short -b'
alias gp='git push'
alias gdd='git diff'
alias gc='git commit'
# http://neurotap.blogspot.com/2012/04/character-level-diff-in-git-gui.html
intra_line_diff='--word-diff-regex="[^[:space:]]|([[:alnum:]]|UTF_8_GUARD)+"'
intra_line_less='LESS="-R +/-\]|\{\+"' # jump directly to changes in diffs
alias gdiff="${intra_line_less} git diff ${intra_line_diff}"
alias gdiff2="git diff -w -U0 --word-diff-regex=[^[:space:]]"
# commit staged changes with the given message
alias gcm='git commit -m'
git_confclicts() {
# list all conflicted files
alias gkl='git ls-files --unmerged | cut -f2 | uniq'
# add changes from all conflicted files
alias gka='git add $(gkl)'
# edit conflicted files
alias gke='vim +"set hlsearch" +"/^[<=>]\{7\}/\( \|$\)" $(gkl)'
# use local version of the given files
alias gko='git checkout --$(test -f .git/MERGE_HEAD && echo ours || echo theirs) --'
# use local version of all conflicted files
alias gkO='gko $(gkl)'
# use upstream version of the given files
alias gkt='git checkout --$(test -f .git/MERGE_HEAD && echo theirs || echo ours) --'
# use upstream version of all conflicted files
alias gkT='gkt $(gkl)'
}
eval "$(hub alias -s)"
[[ -x ${SCRIPT_HOME}/git-cal ]] && alias git-cal=${SCRIPT_HOME}/git-cal
fi
for i in x q Q; eval alias :${i}=\' exit\'
alias iostat='iostat -mtx'
alias yt="youtube-dl"
alias ytt='you-get'
yr(){
${XDG_CONFIG_HOME}/i3/send bscratch toggle youtube
sleep 1s
echo "$@" | xsel -i
xdotool key shift+Insert
}
alias qe='cd *(/om[1])'
if hash ccat > /dev/null; then
alias {cat,hi}='ccat -G String="_default_" -G Plaintext="white" -G Punctuation="blue" -G Literal="fuscia" -G Keyword="fuscia" 2>/dev/null'
fi
alias history='history 0'
alias objdump='objdump -M intel -d'
alias memgrind='valgrind --tool=memcheck "$@" --leak-check=full'
alias cal="task calendar"
if [[ $(whence python) != "" ]]; then
urlencode() { python -c "import sys, urllib; print(urllib.quote_plus(sys.argv[1]))" }
urldecode() { python -c "import sys, urllib; print(urllib.unquote_plus(sys.argv[1]))" }
elif [[ $(whence xxd) != "" ]]; then
urlencode() { echo $@ | tr -d "\n" | xxd -plain | sed "s/\(..\)/%\1/g" }
urldecode() { printf $(echo -n $@ | sed 's/\\/\\\\/g;s/\(%\)\([0-9a-fA-F][0-9a-fA-F]\)/\\x\2/g')"\n" }
fi
zleiab() {
declare -A abk
abk=(
'G' '|& rg -i '
'C' '| wc -l'
'H' '| head'
'T' '| tail'
'N' '&>/dev/null'
'S' '| sort -h '
'V' '|& nvim -'
"jk" "!-2$"
"j2" "!-3$"
"j3" "!-4$"
)
emulate -L zsh
setopt extendedglob
local MATCH
matched_chars='[.-|_a-zA-Z0-9]#'
LBUFFER=${LBUFFER%%(#m)[.-|_a-zA-Z0-9]#}
LBUFFER+=${abk[$MATCH]:-$MATCH}
}
zle -N zleiab
hash journalctl > /dev/null && {
alias log='journalctl -f | ccze -A' #follow log
}
hash iotop > /dev/null && {
alias iotop='sudo iotop -oPa'
alias diskact="sudo iotop -Po"
}
hash nc > /dev/null && alias nyan='nc -v nyancat.dakko.us 23'
alias twitch="streamlink -p mpv twitch.tv/$1 720p60"
alias recordmydesktop="recordmydesktop --no-frame"
alias up="rtv -s unixporn"
alias taco='curl -L git.io/taco'
alias starwars='telnet towel.blinkenlights.nl'
alias -s Dockerfile="docker build - < "
pacnews() { sudo find /etc -name '*.pacnew' | sed -e 's|^/etc/||' -e 's/.pacnew$//' }
alias pkglist="comm -23 <(pacman -Qeq | sort) <(pacman -Qgq base base-devel | sort)"
# upload to imgur with modified zmwangx/imgur
if [[ ${USE_IMGUR_QT} ]]; then
alias img="imgur-upload $@"
else
alias img="imgur-screenshot $@"
fi
alias @r=${SCRIPT_HOME}/music_rename
v(){ ~/bin/v --remote-silent "$@" }
gv(){
~/bin/v --remote-silent ./
~/bin/v --remote-send ":ProjectRootCD<CR>"
~/bin/v --remote-send ":Gitv<CR>"
}
[[ -x =nvim ]] && alias vim=nvim
[[ ${DISPLAY} ]] && alias nvim=v
alias ip='ip -c'
alias fd='fd -H'
alias куищще='reboot'
alias учше='exit'
alias :й=':q'
mimemap() {
default=${1}; shift
for i in $@; do alias -s ${i}=${default}; done
}
alias sp='cdu -idh -s -r -c "#"'
allip(){
netstat -lantp \
| grep ESTABLISHED \
| awk '{print }' \
| awk -F: '{print }' \
| sort -u
}
flac2mp3(){
for infile in "$@"; do
[[ "${infile}" != *.flac ]] && continue
album="$(metaflac --show-tag=album "${infile}" | sed 's/[^=]*=//')"
artist="$(metaflac --show-tag=artist "${infile}" | sed 's/[^=]*=//')"
date="$(metaflac --show-tag=date "${infile}" | sed 's/[^=]*=//')"
title="$(metaflac --show-tag=title "${infile}" | sed 's/[^=]*=//')"
year="$(metaflac --show-tag=date "${infile}" | sed 's/[^=]*=//')"
genre="$(metaflac --show-tag=genre "${infile}" | sed 's/[^=]*=//')"
tracknumber="$(metaflac --show-tag=tracknumber "${infile}" | sed 's/[^=]*=//')"
flac --decode --stdout "${infile}" | lame -b 320 --add-id3v2 \
--tt "${title}" \
--ta "${artist}" \
--tl "${album}" \
--ty "${year}" \
--tn "${tracknumber}" \
--tg "${genre}" - "${infile%.flac}.mp3"
done
}
fun::fonts(){
alias 2023='toilet -f future'
alias gaym='toilet --gay -f mono9 -t'
alias gayf='toilet --gay -f future -t'
alias gayt='toilet --gay -f term -t'
alias gayp='toilet --gay -f pagga -t'
alias metm='toilet --metal -f mono9 -t'
alias metf='toilet --metal -f future -t'
alias mett='toilet --metal -f term -t'
alias metp='toilet --metal -f pagga -t'
alias 3d='figlet -f 3d'
}
+strip_trailing_workspaces(){ sed ${1:+-i} 's/\s\+$//' "$@" }
# --------------------------------------------------------------------
# ZLE-related stuff
inplace_mk_dirs() {
# Press ctrl-xM to create the directory under the cursor or the selected area.
# To select an area press ctrl-@ or ctrl-space and use the cursor.
# Use case: you type "mv abc ~/testa/testb/testc/" and remember that the
# directory does not exist yet -> press ctrl-XM and problem solved
local PATHTOMKDIR
if ((REGION_ACTIVE==1)); then
local F=$MARK T=$CURSOR
if [[ $F -gt $T ]]; then
F=${CURSOR}
T=${MARK}
fi
# get marked area from buffer and eliminate whitespace
PATHTOMKDIR=${BUFFER[F+1,T]%%[[:space:]]##}
PATHTOMKDIR=${PATHTOMKDIR##[[:space:]]##}
else
local bufwords iword
bufwords=(${(z)LBUFFER})
iword=${#bufwords}
bufwords=(${(z)BUFFER})
PATHTOMKDIR="${(Q)bufwords[iword]}"
fi
[[ -z "${PATHTOMKDIR}" ]] && return 1
PATHTOMKDIR=${~PATHTOMKDIR}
if [[ -e "${PATHTOMKDIR}" ]]; then
zle -M " path already exists, doing nothing"
else
zle -M "$(mkdir -p -v "${PATHTOMKDIR}")"
zle end-of-line
fi
}
# thx to github.com/MitchWeaver/dots
75%() { mogrify -resize '75%X75%' "$@" ; }
50%() { mogrify -resize '50%X50%' "$@" ; }
25%() { mogrify -resize '25%X25%' "$@" ; }
# just type '...' to get '../..'
rationalise-dot() {
local MATCH
if [[ $LBUFFER =~ '(^|/| | |'$'\n''|\||;|&)\.\.$' ]]; then
LBUFFER+=/
zle self-insert
zle self-insert
else
zle self-insert
fi
}
zle -N rationalise-dot
# run command line as user root via sudo:
sudo-command-line () {
[[ -z $BUFFER ]] && zle up-history
if [[ ${BUFFER} != sudo\ * ]]; then
BUFFER="sudo ${BUFFER}"
CURSOR=$(( CURSOR+5 ))
fi
}
zle -N sudo-command-line
fg-widget() {
stty icanon echo -inlcr < /dev/tty
stty lnext '^V' quit '^\' susp '^Z' < /dev/tty
zle reset-prompt
if jobs %- >/dev/null 2>&1; then
fg %-
else
fg
fi
}
zle -N fg-widget
__expand-alias() {
zle _expand_alias
zle self-insert
}
expand_aliases() {
zle -N __expand-alias
bindkey -M main ' ' __expand-alias
}
up-one-dir() { pushd .. 2> /dev/null; zle redisplay; zle -M $(pwd); }
back-one-dir() { popd 2> /dev/null; zle redisplay; zle -M $(pwd); }
zle -N up-one-dir
zle -N back-one-dir
magic-abbrev-expand() {
local MATCH
LBUFFER=${LBUFFER%%(#m)[_a-zA-Z0-9]#}
LBUFFER+=${abbreviations[$MATCH]:-$MATCH}
zle self-insert
}
no-magic-abbrev-expand() { LBUFFER+=' ' }
slash-backward-kill-word () {
local WORDCHARS="${WORDCHARS:s@/@}"
zle backward-kill-word
}
zle -N slash-backward-kill-word
|
x
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 | zstyle ':acceptline:*' rehash true
# allow one error for every three characters typed in approximate completer
zstyle ':completion:*:approximate:' \
max-errors 'reply=( $((($#PREFIX+$#SUFFIX)/3 )) numeric )'
# don't complete backup files as executables
zstyle ':completion:*:complete:-command-::commands' \
ignored-patterns '(aptitude-*|*\~)'
# start menu completion only if it could find no unambiguous initial string
zstyle ':completion:*:correct:*' insert-unambiguous true
zstyle ':completion:*:corrections' format "%{${fg[blue]}%}--%{${reset_color}%} %d%{${reset_color}%} - (%{${fg[cyan]}%}errors %e%{${reset_color}%})"
zstyle ':completion:*:descriptions' format "%{${fg[blue]}%}--%{${reset_color}%} %d%{${reset_color}%}%{${reset_color}%}"
zstyle ':completion:*:correct:*' original true
zstyle ':completion:*:-tilde-:*' group-order 'named-directories'
# Don't complete unavailable commands.
zstyle ':completion:*:functions' ignored-patterns '(_*|pre(cmd|exec))'
# insert all expansions for expand completer
zstyle ':completion:*:expand:*' tag-order all-expansions
zstyle ':completion:*:history-words' list false
# activate menu
zstyle ':completion:*:history-words' menu yes
# ignore duplicate entries
zstyle ':completion:*:history-words' remove-all-dups yes
zstyle ':completion:*:history-words' stop yes
# match uppercase from lowercase
zstyle ':completion:*' matcher-list 'm:{a-z}={A-Z}' 'r:|[._-]=* r:|=*' 'l:|=* r:|=*'
# separate matches into groups
zstyle ':completion:*:matches' group 'yes'
zstyle ':completion:*' group-name ''
zstyle ':completion:*' menu select=5
zstyle ':completion:*:messages' format "- %{${fg[cyan]}%}%d%{${reset_color}%} -"
zstyle ':completion:*:options' auto-description '%d'
zstyle ':completion:*:options' description 'yes'
zstyle ':completion:*:*:-subscript-:*' tag-order indexes parameters
zstyle ':completion:*' verbose true
zstyle ':completion:*:-command-:*:' verbose false
zstyle ':completion:*:warnings' format $'%{\e[0;31m%}No matches for:%{\e[0m%} %d'
zstyle ':completion:*:*:zcompile:*' ignored-patterns '(*~|*.zwc)'
zstyle ':completion:correct:' prompt 'correct to: %e'
zstyle ':completion::(^approximate*):*:functions' \
ignored-patterns '_*'
zstyle ':completion:*:manuals' separate-sections true
zstyle ':completion:*:manuals.*' insert-sections true
zstyle ':completion:*:man:*' menu yes select
zstyle ':completion:*' special-dirs ..
zstyle ':completion:*:(mv|cp|file|m|mplayer|mp|mpv):*' \
ignored-patterns '(#i)*.(url|mht)'
zstyle ':completion:*:*:(mplayer|mp|mpv):*' tag-order files
zstyle ':completion:*:*:(mplayer|mp|mpv):*' file-sort name
zstyle ':completion:*:*:(mplayer|mp|mpv):*' menu select auto
zstyle ':completion:*:*:(mplayer*|mp):*' file-patterns '(#i)*.(rmvb|mkv|vob|ts|mp4|m4a|iso|wmv|webm|flv|ogv|avi|mpg|mpeg|iso|nrg|mp3|flac|rm|wv|m4v):files:mplayer\ play *(-/):directories:directories'
zstyle ':completion:*:*:mpg123:*' file-patterns '*.(mp3|MP3):mp3\ files *(-/):directories'
zstyle ':completion:*:*:mpg321:*' file-patterns '*.(mp3|MP3):mp3\ files *(-/):directories'
zstyle ':completion:*:*:ogg123:*' file-patterns '*.(ogg|OGG|flac):ogg\ files *(-/):directories'
zstyle ':completion:*:*:mocp:*' file-patterns '*.(wav|WAV|mp3|MP3|ogg|OGG|flac):ogg\ files *(-/):directories'
zstyle ':completion:*:default' \
select-prompt \
"%{${fg[cyan]}%}Match %{${fg_bold[cyan]}%}%m%{${fg_no_bold[cyan]}%} Line %{${fg_bold[cyan]}%}%l%{${fg_no_bold[blue]}%} %p%{${reset_color}%}"
zstyle ':completion:*:default' \
list-prompt \
"%{${fg[cyan]}%}Line %{${fg_bold[cyan]}%}%l%{${fg_no_bold[cyan]}%} Continue?%{${reset_color}%}"
zstyle ':completion:*:warnings' \
format \
"- %{${fg_no_bold[blue]}%}no match%{${reset_color}%} - %{${fg_no_bold[cyan]}%}%d%{${reset_color}%}"
zstyle ':completion:*:default' list-colors ${${(s.:.)LS_COLORS}%ec=*}
zstyle ':completion:*:options' list-colors '=^(-- *)=00;38;5;222'
zstyle ':completion:*' squeeze-slashes true # e.g. ls foo//bar -> ls foo/bar
[[ -r ~/.ssh/known_hosts ]] && _ssh_hosts=(${${${${${${${(f)"$(<$HOME/.ssh/known_hosts)"}:#[\|]*}%%\ *}%%,*}%%:*}#\[}%\]}) ||
_ssh_hosts=()
[[ -r ~/.ssh/config ]] && _ssh_config_hosts=($(sed -rn 's/host\s+(.+)/\1/ip' "$HOME/.ssh/config" | grep -v "\*" )) ||
_ssh_config_hosts=()
hosts=($HOST "$_ssh_hosts[@]" $_ssh_config_hosts[@] localhost)
zstyle ':completion:*:hosts' hosts ${hosts}
# highlight the original input.
zstyle ':completion:*:original' list-colors "=*=$color[blue];$color[bold]"
# colorize username completion
zstyle ':completion:*:*:*:*:users' list-colors "=*=$color[blue];$color[bg-black]"
# Don't complete uninteresting users...
zstyle ':completion:*:*:*:users' ignored-patterns \
adm amanda apache avahi beaglidx bin cacti canna clamav daemon \
dbus distcache dovecot fax ftp games gdm gkrellmd gopher \
hacluster haldaemon halt hsqldb ident junkbust ldap lp mail \
mailman mailnull mldonkey mysql nagios \
named netdump news nfsnobody nobody nscd ntp nut nx openvpn \
operator pcap postfix postgres privoxy pulse pvm quagga radvd \
rpc rpcuser rpm shutdown squid sshd sync uucp vcsa xfs '_*'
zstyle ':completion:*:wine:*' file-patterns '(#i)*.(exe):exe'
# highlight parameters with uncommon names
zstyle ':completion:*:parameters' list-colors "=[^a-zA-Z]*=$color[cyan]"
# highlight aliases
zstyle ':completion:*:aliases' list-colors "=*=$color[green]"
### highlight the original input.
zstyle ':completion:*:original' list-colors "=*=$color[blue];$color[bold]"
### highlight words like 'esac' or 'end'
zstyle ':completion:*:reserved-words' list-colors "=*=$color[blue]"
### colorize processlist for 'kill'
zstyle ':completion:*:*:kill:*:processes' list-colors "=(#b) #([0-9]#) #([^ ]#)*=$color[cyan]=$color[yellow]=$color[green]"
zstyle ':completion:*:*:kill:*:processes' command 'ps --forest -e -o pid,user,tty,cmd'
zstyle ':completion:*:kill:*' command 'ps -u $USER -o pid,%cpu,tty,cputime,cmd'
zstyle ':completion:*:*:zathura:*' tag-order files
zstyle ':completion:*:*:zathura:*' file-patterns '*(/)|*.{pdf,djvu}'
# make them a little less short, after all (mostly adds -l option to the whatis calll)
zstyle ':completion:*:command-descriptions' command '_call_whatis -l -s 1 -r .\*; _call_whatis -l -s 6 -r .\* 2>/dev/null'
zstyle ':completion:*:*:task:*' verbose yes # taskwarrior
zstyle ':completion:*:*:task:*:descriptions' format '%U%B%d%b%u' # taskwarrior
zstyle ':completion:*:*:task:*' group-name '' # taskwarrior
# command completion: highlight matching part of command, and
zstyle -e ':completion:*:-command-:*:commands' list-colors 'reply=( '\''=(#b)('\''$words[CURRENT]'\''|)*-- #(*)=0=38;5;45=38;5;136'\'' '\''=(#b)('\''$words[CURRENT]'\''|)*=0=38;5;248'\'' )'
# Filename suffixes to ignore during completion (except after rm command)
zstyle ':completion:*:*:(^rm):*:*files' ignored-patterns '*?.o' '*?.c~' '*?.old' '*?.pro'
# This is needed to workaround a bug in _setup:12, causing almost 2 seconds delay for bigger LS_COLORS
# UPDATE: not sure if this is required anymore, with the -command- style above.. keeping it here just to be sure
zstyle ':completion:*:*:-command-:*' list-colors ''
# run rehash on completion so new installed program are found automatically:
_force_rehash() {
(( CURRENT == 1 )) && rehash
return 1
}
## correction
setopt correct
zstyle -e ':completion:*' completer '
if [[ $_last_try != "$HISTNO$BUFFER$CURSOR" ]] ; then
_last_try="$HISTNO$BUFFER$CURSOR"
reply=(_complete _match _ignored _prefix _files)
else
if [[ $words[1] == (rm|mv) ]] ; then
reply=(_complete _files)
else
reply=(_oldlist _expand _force_rehash _complete _ignored _correct _approximate _files)
fi
fi'
[[ -d $ZSHDIR/cache ]] && zstyle ':completion:*' use-cache yes && \
zstyle ':completion::complete:*' cache-path $ZSHDIR/cache/
# use generic completion system for programs not yet defined; (_gnu_generic works
# with commands that provide a --help option with "standard" gnu-like output.)
for compcom in cp deborphan df feh fetchipac head hnb ipacsum mv \
pal stow tail uname ; do
[[ -z ${_comps[$compcom]} ]] && compdef _gnu_generic ${compcom}
done; unset compcom
() {
local -a coreutils
coreutils=(
# /bin
cat chgrp chmod chown cp date dd df dir ln ls mkdir mknod mv readlink
rm rmdir vdir sleep stty sync touch uname mktemp
# /usr/bin
install hostid nice who users pinky stdbuf base64 basename chcon cksum
comm csplit cut dircolors dirname du env expand factor fmt fold groups
head id join link logname md5sum mkfifo nl nproc nohup od paste pathchk
pr printenv ptx runcon seq sha1sum sha224sum sha256sum sha384sum
sha512sum shred shuf sort split stat sum tac tail tee timeout tr
truncate tsort tty unexpand uniq unlink wc whoami yes arch touch
)
for i in $coreutils; do
# all which don't already have one
# at time of this writing, those are:
# /bin
# chgrp chmod chown cp date dd df ln ls mkdir rm rmdir stty sync
# touch uname
# /usr/bin
# nice comm cut du env groups id join logname md5sum nohup printenv
# sort stat unexpand uniq whoami
(( $+_comps[$i] )) || compdef _gnu_generic $i
done
}
__archive_or_uri(){
_alternative \
'files:Archives:_files -g "*.(#l)(tar.bz2|tbz2|tbz|tar.gz|tgz|tar.xz|txz|tar.lzma|tar|rar|lzh|7z|zip|jar|deb|bz2|gz|Z|xz|lzma)"' \
'_urls:Remote Archives:_urls'
}
_simple_extract(){
_arguments \
'-d[delete original archivefile after extraction]' \
'*:Archive Or Uri:__archive_or_uri'
}
compdef _simple_extract simple-extract
autoload -U select-word-style backward-kill-word-match backward-word-match forward-word-match
select-word-style shell
zle -N backward-kill-word-match
zle -N backward-word-match
zle -N forward-word-match
# for backward-kill, all but / are word chars (ie, delete word up to last directory)
zstyle ':zle:backward-kill-word*' word-style standard
zstyle ':zle:*kill*' word-chars '*?_-.[]~=&;!#$%^(){}<>'
expand-or-complete-with-dots() {
echo -n "\e[31m......\e[0m"
zle expand-or-complete
zle redisplay
}
zle -N expand-or-complete-with-dots
# Load completion from bash, which isn't available in zsh yet.
bash_completions=()
if [ -n "$commands[vzctl]" ] ; then
bash_completions+=(/etc/bash_completion.d/vzctl.sh)
fi
if (( $#bash_completions )); then
if ! which complete &>/dev/null; then
autoload -Uz bashcompinit
if which bashcompinit &>/dev/null; then
bashcompinit
fi
fi
bash_source /etc/bash_completion.d/vzctl.sh
fi
function expand-or-complete-with-dots() {
echo -n "\e[36m-=--...--=-\e[0m"
zle expand-or-complete
zle redisplay
}
zle -N expand-or-complete-with-dots
bindkey "^I" expand-or-complete-with-dots
|
x
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | #!/usr/bin/zsh
bindkey -e
zmodload -i zsh/parameter
#k# Kill left-side word or everything up to next slash
bindkey '\ev' slash-backward-kill-word
bindkey '^r' history-incremental-pattern-search-backward
bindkey '^s' history-incremental-pattern-search-forward
bindkey "^[+" up-one-dir
bindkey "^[=" back-one-dir
zle -N magic-abbrev-expand
zle -N no-magic-abbrev-expand
bindkey " " magic-abbrev-expand
bindkey "^x " no-magic-abbrev-expand
bindkey . rationalise-dot
autoload up-line-or-beginning-search
autoload down-line-or-beginning-search
zle -N up-line-or-beginning-search
zle -N down-line-or-beginning-search
bindkey "^[[A" up-line-or-beginning-search
bindkey "^[[B" down-line-or-beginning-search
bindkey '\ei' menu-complete # menu completion via esc-i
# do history expansion on space
bindkey " " magic-space
bindkey ",." zleiab
bindkey -M emacs "^[w" vi-cmd-mode
bindkey -M emacs "^X^F" vi-find-next-char
# accept a completion and try to complete again by using menu
# completion; very useful with completing directories
# by using 'undo' one's got a simple file browser
bindkey -M menuselect '^o' accept-and-infer-next-history
bindkey -M menuselect 'h' vi-backward-char
bindkey -M menuselect 'j' vi-down-line-or-history
bindkey -M menuselect 'k' vi-up-line-or-history
bindkey -M menuselect 'l' vi-forward-char
bindkey -M menuselect 'i' accept-and-menu-complete
bindkey -M menuselect "+" accept-and-menu-complete
bindkey -M menuselect "^[[2~" accept-and-menu-complete
bindkey -M menuselect 'o' accept-and-infer-next-history
bindkey -M menuselect '\e^M' accept-and-menu-complete
# also use + and INSERT since it's easier to press repeatedly
bindkey . rationalise-dot
# without this, typing a . aborts incremental history search
bindkey -M isearch . self-insert
# load the lookup subsystem if it's available on the system
zrcautoload lookupinit && lookupinit
zle -N inplace_mk_dirs && bindkey '^xM' inplace_mk_dirs
bindkey -M emacs "^XD" describe-key-briefly
bindkey -M emacs "^Z" fg-widget
bindkey -M vicmd "^Z" fg-widget
bindkey -M viins "^Z" fg-widget
bindkey '^j' fasd-complete # C-x C-a to do fasd-complete (files and directories)
local jump_dirs=( ~/1st_level ~/dw ~/tmp ~/src/1st_level ~/vid/new)
for index in $(seq 1 $((${#jump_dirs[@]} ))); do
bindkey -s "${index}" "cd ${jump_dirs[$index]/${HOME}/~}
"
done
|
x
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 | # MIT (c) Wenxuan Zhang
forgit::warn() { printf "%b[Warn]%b %s\n" '\e[0;33m' '\e[0m' "$@" >&2; }
forgit::info() { printf "%b[Info]%b %s\n" '\e[0;32m' '\e[0m' "$@" >&2; }
forgit::inside_work_tree() { git rev-parse --is-inside-work-tree >/dev/null; }
# https://github.com/so-fancy/diff-so-fancy
hash diff-so-fancy &>/dev/null && forgit_fancy='|diff-so-fancy'
# https://github.com/wfxr/emoji-cli
hash emojify &>/dev/null && forgit_emojify='|emojify'
# git commit viewer
forgit::log() {
forgit::inside_work_tree || return 1
local cmd opts
cmd="echo {} |grep -Eo '[a-f0-9]+' |head -1 |xargs -I% git show --color=always % $* $forgit_emojify $forgit_fancy"
opts="
$FORGIT_FZF_DEFAULT_OPTS
+s +m --tiebreak=index --preview=\"$cmd\"
--bind=\"enter:execute($cmd |LESS='-R' less)\"
--bind=\"ctrl-y:execute-silent(echo {} |grep -Eo '[a-f0-9]+' | head -1 | tr -d '\n' |${FORGIT_COPY_CMD:-pbcopy})\"
$FORGIT_LOG_FZF_OPTS
"
eval "git log --graph --color=always --format='%C(auto)%h%d %s %C(black)%C(bold)%cr' $* $forgit_emojify" |
FZF_DEFAULT_OPTS="$opts" fzf
}
# git diff viewer
forgit::diff() {
forgit::inside_work_tree || return 1
local cmd files opts commit
[[ $# -ne 0 ]] && {
if git rev-parse "$1" -- &>/dev/null ; then
commit="$1" && files=("${@:2}")
else
files=("$@")
fi
}
cmd="git diff --color=always $commit -- {} $forgit_emojify $forgit_fancy"
opts="
$FORGIT_FZF_DEFAULT_OPTS
+m -0 --preview=\"$cmd\" --bind=\"enter:execute($cmd |LESS='-R' less)\"
$FORGIT_DIFF_FZF_OPTS
"
eval "git diff --name-only --relative $commit -- ${files[*]}"|
FZF_DEFAULT_OPTS="$opts" fzf
}
# git add selector
forgit::add() {
forgit::inside_work_tree || return 1
local changed unmerged untracked files opts
changed=$(git config --get-color color.status.changed red)
unmerged=$(git config --get-color color.status.unmerged red)
untracked=$(git config --get-color color.status.untracked red)
opts="
$FORGIT_FZF_DEFAULT_OPTS
-0 -m --nth 2..,..
--preview=\"git diff --color=always -- {-1} $forgit_emojify $forgit_fancy\"
$FORGIT_ADD_FZF_OPTS
"
files=$(git -c color.status=always status --short |
grep -F -e "$changed" -e "$unmerged" -e "$untracked" |
awk '{printf "[%10s] ", $1; $1=""; print $0}' |
FZF_DEFAULT_OPTS="$opts" fzf | cut -d] -f2 |
sed 's/.* -> //') # for rename case
[[ -n "$files" ]] && echo "$files" |xargs -I{} git add {} && git status --short && return
echo 'Nothing to add.'
}
# git reset HEAD (unstage) selector
forgit::reset::head() {
forgit::inside_work_tree || return 1
local cmd files opts
cmd="git diff --cached --color=always -- {} $forgit_emojify $forgit_fancy"
opts="
$FORGIT_FZF_DEFAULT_OPTS
-m -0 --preview=\"$cmd\"
$FORGIT_RESET_HEAD_FZF_OPTS
"
files="$(git diff --cached --name-only | FZF_DEFAULT_OPTS="$opts" fzf)"
[[ -n "$files" ]] && echo "$files" |xargs -I{} git reset HEAD {} && git status --short && return
echo 'Nothing to unstage.'
}
# git checkout-restore selector
forgit::restore() {
forgit::inside_work_tree || return 1
local cmd files opts
cmd="git diff --color=always -- {} $forgit_emojify $forgit_fancy"
opts="
$FORGIT_FZF_DEFAULT_OPTS
-m -0 --preview=\"$cmd\"
$FORGIT_CHECKOUT_FZF_OPTS
"
files="$(git ls-files --modified "$(git rev-parse --show-toplevel)"| FZF_DEFAULT_OPTS="$opts" fzf)"
[[ -n "$files" ]] && echo "$files" |xargs -I{} git checkout {} && git status --short && return
echo 'Nothing to restore.'
}
# git stash viewer
forgit::stash::show() {
forgit::inside_work_tree || return 1
local cmd opts
cmd="git stash show \$(echo {}| cut -d: -f1) --color=always --ext-diff $forgit_fancy"
opts="
$FORGIT_FZF_DEFAULT_OPTS
+s +m -0 --tiebreak=index --preview=\"$cmd\" --bind=\"enter:execute($cmd |LESS='-R' less)\"
$FORGIT_STASH_FZF_OPTS
"
git stash list | FZF_DEFAULT_OPTS="$opts" fzf
}
# git clean selector
forgit::clean() {
forgit::inside_work_tree || return 1
local files opts
opts="
$FORGIT_FZF_DEFAULT_OPTS
-m -0
$FORGIT_CLEAN_FZF_OPTS
"
# Note: Postfix '/' in directory path should be removed. Otherwise the directory itself will not be removed.
files=$(git clean -xdfn "$@"| awk '{print $3}'| FZF_DEFAULT_OPTS="$opts" fzf |sed 's#/$##')
[[ -n "$files" ]] && echo "$files" |xargs -I% git clean -xdf % && return
echo 'Nothing to clean.'
}
# git ignore generator
export FORGIT_GI_REPO_REMOTE=${FORGIT_GI_REPO_REMOTE:-https://github.com/dvcs/gitignore}
export FORGIT_GI_REPO_LOCAL=${FORGIT_GI_REPO_LOCAL:-~/.forgit/gi/repos/dvcs/gitignore}
export FORGIT_GI_TEMPLATES=${FORGIT_GI_TEMPLATES:-$FORGIT_GI_REPO_LOCAL/templates}
forgit::ignore() {
[ -d "$FORGIT_GI_REPO_LOCAL" ] || forgit::ignore::update
local IFS cmd args cat opts
# https://github.com/sharkdp/bat.git
hash bat &>/dev/null && cat='bat -l gitignore --color=always' || cat="cat"
cmd="$cat $FORGIT_GI_TEMPLATES/{2}{,.gitignore} 2>/dev/null"
opts="
$FORGIT_FZF_DEFAULT_OPTS
-m --preview=\"$cmd\" --preview-window='right:70%'
$FORGIT_IGNORE_FZF_OPTS
"
# shellcheck disable=SC2206,2207
IFS=$'\n' args=($@) && [[ $# -eq 0 ]] && args=($(forgit::ignore::list | nl -nrn -w4 -s' ' |
FZF_DEFAULT_OPTS="$opts" fzf |awk '{print $2}'))
[ ${#args[@]} -eq 0 ] && return 1
# shellcheck disable=SC2068
if hash bat &>/dev/null; then
forgit::ignore::get ${args[@]} | bat -l gitignore
else
forgit::ignore::get ${args[@]}
fi
}
forgit::ignore::update() {
if [[ -d "$FORGIT_GI_REPO_LOCAL" ]]; then
forgit::info 'Updating gitignore repo...'
(cd "$FORGIT_GI_REPO_LOCAL" && git pull --no-rebase --ff) || return 1
else
forgit::info 'Initializing gitignore repo...'
git clone --depth=1 "$FORGIT_GI_REPO_REMOTE" "$FORGIT_GI_REPO_LOCAL"
fi
}
forgit::ignore::get() {
local item filename header
for item in "$@"; do
if filename=$(find -L "$FORGIT_GI_TEMPLATES" -type f \( -iname "${item}.gitignore" -o -iname "${item}" \) -print -quit); then
[[ -z "$filename" ]] && forgit::warn "No gitignore template found for '$item'." && continue
header="${filename##*/}" && header="${header%.gitignore}"
echo "### $header" && cat "$filename" && echo
fi
done
}
forgit::ignore::list() {
find "$FORGIT_GI_TEMPLATES" -print |sed -e 's#.gitignore$##' -e 's#.*/##' | sort -fu
}
forgit::ignore::clean() {
setopt localoptions rmstarsilent
[[ -d "$FORGIT_GI_REPO_LOCAL" ]] && rm -rf "$FORGIT_GI_REPO_LOCAL"
}
FORGIT_FZF_DEFAULT_OPTS="
$FZF_DEFAULT_OPTS
--ansi
--height='80%'
--bind='alt-k:preview-up,alt-p:preview-up'
--bind='alt-j:preview-down,alt-n:preview-down'
--bind='ctrl-r:toggle-all'
--bind='ctrl-s:toggle-sort'
--bind='?:toggle-preview'
--bind='alt-w:toggle-preview-wrap'
--preview-window='right:60%'
$FORGIT_FZF_DEFAULT_OPTS
"
# register aliases
# shellcheck disable=SC2139
if [[ -z "$FORGIT_NO_ALIASES" ]]; then
alias "${forgit_add:-ga}"='forgit::add'
alias "${forgit_reset_head:-grh}"='forgit::reset::head'
alias "${forgit_log:-glo}"='forgit::log'
alias "${forgit_diff:-gd}"='forgit::diff'
alias "${forgit_ignore:-gi}"='forgit::ignore'
alias "${forgit_restore:-gcf}"='forgit::restore'
alias "${forgit_clean:-gclean}"='forgit::clean'
alias "${forgit_stash_show:-gss}"='forgit::stash::show'
fi
|
x
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | #!/usr/bin/env zsh
#date +%H:%M:%S.%N
# Parse getopt-style help texts for options
# and generate zsh(1) completion functions.
# http://github.com/RobSis/zsh-completion-generator
SCRIPT_SOURCE=${0:A:h}
if [ -z $GENCOMPL_FPATH ]; then
directory="$SCRIPT_SOURCE/compdef"
else
directory="$GENCOMPL_FPATH"
fi
# don't overwrite existing functions
fpath=($fpath $directory)
# which python to use
if [ -z $GENCOMPL_PY ]; then
python=python
else
python=$GENCOMPL_PY
fi
mkdir -p $directory
# define default programs here:
programs=( "cat" "nl" "tr" "df --help" )
for prg in "${programs[@]}"; do
name=$prg
help=--help
if [[ $prg =~ " " ]]; then
i=( "${(s/ /)prg}" )
name=$i[1]
if [ -n "$i[2]" ]; then
help="$i[2]"
fi
fi
test -f $directory/_$name ||\
$name $help 2>&1 | $python $SCRIPT_SOURCE/help2comp.py $name > $directory/_$name || rm -f $directory/_$name
done
# or use function in shell:
gencomp() {
if [ -z "$1" ]; then
echo "Usage: gencomp program [--argument-for-help-text]"
echo
return 1
fi
help=--help
if [ -n "$2" ]; then
help=$2
fi
$1 $help 2>&1 | $python $SCRIPT_SOURCE/help2comp.py $1 > $directory/_$1 || ( rm -f $directory/_$1 &&\
echo "No options found for '$1'." )
}
#date +%H:%M:%S.%N # profiling info
|
x
1 2 | source /usr/share/fzf/completion.zsh
source /usr/share/fzf/key-bindings.zsh
|
x
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 | #!/usr/bin/zsh
# -------------------------------------------------------------------------------------------------
# Copyright (c) 2010-2016 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
# -------------------------------------------------------------------------------------------------
# First of all, ensure predictable parsing.
zsh_highlight__aliases=`builtin alias -Lm '[^+]*'`
# In zsh <= 5.2, `alias -L` emits aliases that begin with a plus sign ('alias -- +foo=42')
# them without a '--' guard, so they don't round trip.
#
# Hence, we exclude them from unaliasing:
builtin unalias -m '[^+]*'
# -------------------------------------------------------------------------------------------------
# Core highlighting update system
# -------------------------------------------------------------------------------------------------
# Use workaround for bug in ZSH?
# zsh-users/zsh@48cadf4 http://www.zsh.org/mla/workers//2017/msg00034.html
autoload -Uz is-at-least
if is-at-least 5.4; then
zsh_highlight__pat_static_bug=false
else
zsh_highlight__pat_static_bug=true
fi
# 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()
{
# Store the previous command return code to restore it whatever happens.
local ret=$?
# Remove all highlighting in isearch, so that only the underlining done by zsh itself remains.
# For details see FAQ entry 'Why does syntax highlighting not work while searching history?'.
# This disables highlighting during isearch (for reasons explained in README.md) unless zsh is new enough
# and doesn't have the pattern matching bug
if [[ $WIDGET == zle-isearch-update ]] && { $zsh_highlight__pat_static_bug || ! (( $+ISEARCHMATCH_ACTIVE )) }; then
region_highlight=()
return $ret
fi
# Before we 'emulate -L', save the user's options
local -A zsyh_user_options
if zmodload -e zsh/parameter; then
zsyh_user_options=("${(@kv)options}")
else
local canonical_options onoff option raw_options
raw_options=(${(f)"$(emulate -R zsh; set -o)"})
canonical_options=(${${${(M)raw_options:#*off}%% *}#no} ${${(M)raw_options:#*on}%% *})
for option in $canonical_options; do
[[ -o $option ]]
# This variable cannot be eliminated c.f. workers/42101.
onoff=${${=:-off on}[2-$?]}
zsyh_user_options+=($option $onoff)
done
fi
typeset -r zsyh_user_options
emulate -L zsh
setopt localoptions warncreateglobal
local REPLY # don't leak $REPLY into global scope
# 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
# Reset region highlight to build it from scratch
typeset -ga region_highlight
region_highlight=();
{
local cache_place
local -a region_highlight_copy
# Select which highlighters in ZSH_HIGHLIGHT_HIGHLIGHTERS need to be invoked.
local highlighter; for highlighter in $ZSH_HIGHLIGHT_HIGHLIGHTERS; do
# eval cache place for current highlighter and prepare it
cache_place="_zsh_highlight__highlighter_${highlighter}_cache"
typeset -ga ${cache_place}
# If highlighter needs to be invoked
if ! type "_zsh_highlight_highlighter_${highlighter}_predicate" >&/dev/null; then
echo "zsh-syntax-highlighting: warning: disabling the ${(qq)highlighter} highlighter as it has not been loaded" >&2
# TODO: use ${(b)} rather than ${(q)} if supported
ZSH_HIGHLIGHT_HIGHLIGHTERS=( ${ZSH_HIGHLIGHT_HIGHLIGHTERS:#${highlighter}} )
elif "_zsh_highlight_highlighter_${highlighter}_predicate"; then
# save a copy, and cleanup region_highlight
region_highlight_copy=("${region_highlight[@]}")
region_highlight=()
# Execute highlighter and save result
{
"_zsh_highlight_highlighter_${highlighter}_paint"
} always {
: ${(AP)cache_place::="${region_highlight[@]}"}
}
# Restore saved region_highlight
region_highlight=("${region_highlight_copy[@]}")
fi
# Use value form cache if any cached
region_highlight+=("${(@P)cache_place}")
done
# Re-apply zle_highlight settings
# region
if (( REGION_ACTIVE == 1 )); then
_zsh_highlight_apply_zle_highlight region standout "$MARK" "$CURSOR"
elif (( REGION_ACTIVE == 2 )); then
() {
local needle=$'\n'
integer min max
if (( MARK > CURSOR )) ; then
min=$CURSOR max=$MARK
else
min=$MARK max=$CURSOR
fi
# CURSOR and MARK are 0 indexed between letters like region_highlight
# Do not include the newline in the highlight
(( min = ${BUFFER[(Ib:min:)$needle]} ))
(( max = ${BUFFER[(ib:max:)$needle]} - 1 ))
_zsh_highlight_apply_zle_highlight region standout "$min" "$max"
}
fi
# yank / paste (zsh-5.1.1 and newer)
(( $+YANK_ACTIVE )) && (( YANK_ACTIVE )) && _zsh_highlight_apply_zle_highlight paste standout "$YANK_START" "$YANK_END"
# isearch
(( $+ISEARCHMATCH_ACTIVE )) && (( ISEARCHMATCH_ACTIVE )) && _zsh_highlight_apply_zle_highlight isearch underline "$ISEARCHMATCH_START" "$ISEARCHMATCH_END"
# suffix
(( $+SUFFIX_ACTIVE )) && (( SUFFIX_ACTIVE )) && _zsh_highlight_apply_zle_highlight suffix bold "$SUFFIX_START" "$SUFFIX_END"
return $ret
} always {
typeset -g _ZSH_HIGHLIGHT_PRIOR_BUFFER="$BUFFER"
typeset -gi _ZSH_HIGHLIGHT_PRIOR_CURSOR=$CURSOR
}
}
# Apply highlighting based on entries in the zle_highlight array.
# This function takes four arguments:
# 1. The exact entry (no patterns) in the zle_highlight array:
# region, paste, isearch, or suffix
# 2. The default highlighting that should be applied if the entry is unset
# 3. and 4. Two integer values describing the beginning and end of the
# range. The order does not matter.
_zsh_highlight_apply_zle_highlight() {
local entry="$1" default="$2"
integer first="$3" second="$4"
# read the relevant entry from zle_highlight
#
# ### In zsh≥5.0.8 we'd use ${(b)entry}, but we support older zsh's, so we don't
# ### add (b). The only effect is on the failure mode for callers that violate
# ### the precondition.
local region="${zle_highlight[(r)${entry}:*]-}"
if [[ -z "$region" ]]; then
# entry not specified at all, use default value
region=$default
else
# strip prefix
region="${region#${entry}:}"
# no highlighting when set to the empty string or to 'none'
if [[ -z "$region" ]] || [[ "$region" == none ]]; then
return
fi
fi
integer start end
if (( first < second )); then
start=$first end=$second
else
start=$second end=$first
fi
region_highlight+=("$start $end $region")
}
# -------------------------------------------------------------------------------------------------
# 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))
}
# Add a highlight defined by ZSH_HIGHLIGHT_STYLES.
#
# Should be used by all highlighters aside from 'pattern' (cf. ZSH_HIGHLIGHT_PATTERN).
# Overwritten in tests/test-highlighting.zsh when testing.
_zsh_highlight_add_highlight()
{
local -i start end
local highlight
start=$1
end=$2
shift 2
for highlight; do
if (( $+ZSH_HIGHLIGHT_STYLES[$highlight] )); then
region_highlight+=("$start $end $ZSH_HIGHLIGHT_STYLES[$highlight]")
break
fi
done
}
# -------------------------------------------------------------------------------------------------
# Setup functions
# -------------------------------------------------------------------------------------------------
# Helper for _zsh_highlight_bind_widgets
# $1 is name of widget to call
_zsh_highlight_call_widget()
{
builtin zle "$@" &&
_zsh_highlight
}
# Rebind all ZLE widgets to make them invoke _zsh_highlights.
_zsh_highlight_bind_widgets()
{
setopt localoptions noksharrays
typeset -F SECONDS
local prefix=orig-s$SECONDS-r$RANDOM # unique each time, in case we're sourced more than once
# Load ZSH module zsh/zleparameter, needed to override user defined widgets.
zmodload zsh/zleparameter 2>/dev/null || {
print -r -- >&2 'zsh-syntax-highlighting: failed loading zsh/zleparameter.'
return 1
}
# Override ZLE widgets to make them invoke _zsh_highlight.
local -U widgets_to_bind
widgets_to_bind=(${${(k)widgets}:#(.*|run-help|which-command|beep|set-local-history|yank|yank-pop)})
# Always wrap special zle-line-finish widget. This is needed to decide if the
# current line ends and special highlighting logic needs to be applied.
# E.g. remove cursor imprint, don't highlight partial paths, ...
widgets_to_bind+=(zle-line-finish)
# Always wrap special zle-isearch-update widget to be notified of updates in isearch.
# This is needed because we need to disable highlighting in that case.
widgets_to_bind+=(zle-isearch-update)
local cur_widget
for cur_widget in $widgets_to_bind; do
case ${widgets[$cur_widget]:-""} in
# Already rebound event: do nothing.
user:_zsh_highlight_widget_*);;
# The "eval"'s are required to make $cur_widget a closure: the value of the parameter at function
# definition time is used.
#
# We can't use ${0/_zsh_highlight_widget_} because these widgets are always invoked with
# NO_function_argzero, regardless of the option's setting here.
# User defined widget: override and rebind old one with prefix "orig-".
user:*) zle -N $prefix-$cur_widget ${widgets[$cur_widget]#*:}
eval "_zsh_highlight_widget_${(q)prefix}-${(q)cur_widget}() { _zsh_highlight_call_widget ${(q)prefix}-${(q)cur_widget} -- \"\$@\" }"
zle -N $cur_widget _zsh_highlight_widget_$prefix-$cur_widget;;
# Completion widget: override and rebind old one with prefix "orig-".
completion:*) zle -C $prefix-$cur_widget ${${(s.:.)widgets[$cur_widget]}[2,3]}
eval "_zsh_highlight_widget_${(q)prefix}-${(q)cur_widget}() { _zsh_highlight_call_widget ${(q)prefix}-${(q)cur_widget} -- \"\$@\" }"
zle -N $cur_widget _zsh_highlight_widget_$prefix-$cur_widget;;
# Builtin widget: override and make it call the builtin ".widget".
builtin) eval "_zsh_highlight_widget_${(q)prefix}-${(q)cur_widget}() { _zsh_highlight_call_widget .${(q)cur_widget} -- \"\$@\" }"
zle -N $cur_widget _zsh_highlight_widget_$prefix-$cur_widget;;
# Incomplete or nonexistent widget: Bind to z-sy-h directly.
*)
if [[ $cur_widget == zle-* ]] && (( ! ${+widgets[$cur_widget]} )); then
_zsh_highlight_widget_${cur_widget}() { :; _zsh_highlight }
zle -N $cur_widget _zsh_highlight_widget_$cur_widget
else
# Default: unhandled case.
print -r -- >&2 "zsh-syntax-highlighting: unhandled ZLE widget ${(qq)cur_widget}"
print -r -- >&2 "zsh-syntax-highlighting: (This is sometimes caused by doing \`bindkey <keys> ${(q-)cur_widget}\` without creating the ${(qq)cur_widget} widget with \`zle -N\` or \`zle -C\`.)"
fi
esac
done
}
# Load highlighters from directory.
#
# Arguments:
# 1) Path to the highlighters directory.
_zsh_highlight_load_highlighters()
{
setopt localoptions noksharrays bareglobqual
# Check the directory exists.
[[ -d "$1" ]] || {
print -r -- >&2 "zsh-syntax-highlighting: highlighters directory ${(qq)1} not found."
return 1
}
# Load highlighters from highlighters directory and check they define required functions.
local highlighter highlighter_dir
for highlighter ({main,brackets,pattern}); do
[[ -f "${ZDOTDIR}/highlighters/${highlighter}-highlighter.zsh" ]] &&
. "${ZDOTDIR}/highlighters/${highlighter}-highlighter.zsh"
if type "_zsh_highlight_highlighter_${highlighter}_paint" &> /dev/null &&
type "_zsh_highlight_highlighter_${highlighter}_predicate" &> /dev/null;
then
# New (0.5.0) function names
elif type "_zsh_highlight_${highlighter}_highlighter" &> /dev/null &&
type "_zsh_highlight_${highlighter}_highlighter_predicate" &> /dev/null;
then
# Old (0.4.x) function names
if false; then
# TODO: only show this warning for plugin authors/maintainers, not for end users
print -r -- >&2 "zsh-syntax-highlighting: warning: ${(qq)highlighter} highlighter uses deprecated entry point names; please ask its maintainer to update it: https://github.com/zsh-users/zsh-syntax-highlighting/issues/329"
fi
# Make it work.
eval "_zsh_highlight_highlighter_${(q)highlighter}_paint() { _zsh_highlight_${(q)highlighter}_highlighter \"\$@\" }"
eval "_zsh_highlight_highlighter_${(q)highlighter}_predicate() { _zsh_highlight_${(q)highlighter}_highlighter_predicate \"\$@\" }"
else
print -r -- >&2 "zsh-syntax-highlighting: ${(qq)highlighter} highlighter should define both required functions '_zsh_highlight_highlighter_${highlighter}_paint' and '_zsh_highlight_highlighter_${highlighter}_predicate' in ${(qq):-"highlighters/${highlighter}-highlighter.zsh"}."
fi
done
}
# -------------------------------------------------------------------------------------------------
# Setup
# -------------------------------------------------------------------------------------------------
# Try binding widgets.
_zsh_highlight_bind_widgets || {
print -r -- >&2 'zsh-syntax-highlighting: failed binding ZLE widgets, exiting.'
return 1
}
# Resolve highlighters directory location.
_zsh_highlight_load_highlighters "${ZSH_HIGHLIGHT_HIGHLIGHTERS_DIR:-${${0:A}:h}/highlighters}" || {
print -r -- >&2 'zsh-syntax-highlighting: failed loading highlighters, exiting.'
return 1
}
# Reset scratch variables when commandline is done.
_zsh_highlight_preexec_hook() {
typeset -g _ZSH_HIGHLIGHT_PRIOR_BUFFER=
typeset -gi _ZSH_HIGHLIGHT_PRIOR_CURSOR=
}
autoload -Uz add-zsh-hook
add-zsh-hook preexec _zsh_highlight_preexec_hook 2>/dev/null || {
print -r -- >&2 'zsh-syntax-highlighting: failed loading add-zsh-hook.'
}
# Load zsh/parameter module if available
zmodload zsh/parameter 2>/dev/null || true
# Initialize the array of active highlighters if needed.
[[ $#ZSH_HIGHLIGHT_HIGHLIGHTERS -eq 0 ]] && \
ZSH_HIGHLIGHT_HIGHLIGHTERS=(main brackets pattern)
# Restore the aliases we unned
eval "$zsh_highlight__aliases"
builtin unset zsh_highlight__aliases
# Set $?.
true
ZSH_HIGHLIGHT_PATTERNS+=('[<>\|\\|$!&;/]' fg=blue)
ZSH_HIGHLIGHT_PATTERNS+=('~' fg=2)
ZSH_HIGHLIGHT_MAXLENGTH=350
|
x
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | #!/bin/zsh
source "${ZDOTDIR}/03-helpers.zsh"
autoload colors && colors
function eat () {
prog=${0##*/}
local pass="*"
filename="$@"
xclip -in -selection c < "${filename}"
zwrap "${pass} ${txtund}"${filename##*/}"${txtrst} copied to clipboard"
}
function main() {
readonly ftype_pref="ftype-"
readonly dircolors_location="${XDG_CONFIG_HOME}/dircolors/.dircolors"
readonly tmp_file="$(mktemp)"
readonly ftype_arr="/tmp/ftype_arr"
readonly ftype_rule="/tmp/ftype_rule"
readonly is_bold="\\(01;\|;1\\)"
readonly is_italic="\\(03;\|;3\\)"
readonly is_uline="\\(04;\|;4\\)"
readonly bold_regex="/${is_bold}/"
readonly italic_regex="/${is_italic}/"
readonly uline_regex="/${is_uline}/"
readonly fg_eq="38;5;"
readonly bg_eq="48;5;"
egrep '^[.*]' ${1:-$dircolors_location} \
|sed 's/#.*//' \
|sed "s/^\.\W*/${ftype_pref}/" > "${tmp_file}"
zwrap "-----------------------------"
zwrap "You should handle it by hand:"
zwrap "-----------------------------"
local -a sed_args=(
-e "s/${fg_eq}/fg=/"
-e "s/${bg_eq}/bg=/g"
-e "${bold_regex}s/$/,bold/"
-e "${italic_regex}s/$/,italic/"
-e "${uline_regex}s/$/,underline/"
-e "s/00;//"
-e "s/${is_bold}//"
-e "s/${is_uline}//"
-e "s/${is_italic}//"
-e "s/;/,/g"
-e "/\ 3[0-9][0-9]*/s/3/fg=/"
-e "s/, //g"
)
egrep "^${ftype_pref}" -v "${tmp_file}"
egrep "^${ftype_pref}" "${tmp_file}" | sed ${sed_args} > "${ftype_arr}"
nohup zsh -c "nvim +'Tabularize/[bf]g=.*' "${ftype_arr}" +'wq'" > /dev/null 2>&1
sed "s/^${ftype_pref}//" "${ftype_arr}" |awk '{print "*."$1") style=ftype-"$1" ;;"}' > "${ftype_rule}"
nohup zsh -c "nvim +'Tabularize/)\zs ' "${ftype_rule}" +'wq'" > /dev/null 2>&1
for t in "${ftype_arr}" "${ftype_rule}"; eat "${t}"
rm "${tmp_file}"
cp -iv "${ftype_arr}" ~/.zsh/highlighters/ft_list.zsh
start_line=$[$(grep -n '#.*Begining of ftype array.*@@@@' ~/.zsh/highlighters/main-highlighter.zsh|cut -f1 -d:)+1]
end_line=$[$(grep -n '#.*End of ftype array.*@@@@' ~/.zsh/highlighters/main-highlighter.zsh|cut -f1 -d:)-1]
if [[ "${start_line}" != "" && "${end_line}" != "" ]]; then
# Delete highlight array from file
sed -i "${start_line},${end_line}d" ~/.zsh/highlighters/main-highlighter.zsh > /tmp/test
new_start_line=$[$(grep -n '#.*Begining of ftype array.*@@@@' ~/.zsh/highlighters/main-highlighter.zsh|cut -f1 -d:)]
while read line; do
sed -i "${new_start_line}a \\\t\t${line}" ~/.zsh/highlighters/main-highlighter.zsh
done < "${ftype_rule}"
fi
}
main "${1}"
|
x
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | #!/usr/bin/zsh
prompt_end="∣%F{25}${PROMPT_FST}%B%F{26}${PROMPT_SND}%B%f "
neg_user_pretok="${PROMPT_LHS}%f"
[[ ${UID} -ne 0 ]] && _neg_promptcolor="${TILDA_COLOR}" && _neg_user_pretoken="${MAIN_COLOR}${PROMPT_LHS}%f"
[[ ${UID} -ne 0 ]] && _neg_promptcolor="${TILDA_COLOR}" && _neg_user_token="${MAIN_COLOR}${PROMPT_RHS}${prompt_end}"
setopt sh_word_split
local _neg_dyn_pwd=""
local _neg_full_path="$(pwd)"
local _neg_tilda_path=${_neg_full_path/${HOME}/\~}
# write the home directory as a tilda
[[ ${_neg_tilda_path[2,-1]} == "/" ]] && _neg_tilda_path=${_neg_tilda_path[2,-1]}
# otherwise the first element of split_path would be empty.
local _neg_forwards_in_tilda_path=${_neg_tilda_path//[^["\/"]/}
# remove everything that is not a "/"
local _neg_number_of_elements_in_tilda_path=$(( $#_neg_forwards_in_tilda_path + 1 ))
# we removed the first forward slash, so we need one more element than the number of slashes
local _neg_saveIFS="${IFS}"
IFS="/"
local _neg_split_path=(${_neg_tilda_path})
local _neg_start_of_loop=1
local _neg_end_of_loop=${_neg_number_of_elements_in_tilda_path}
for i in {$_neg_start_of_loop..$_neg_end_of_loop}; do
if [[ $i == $_neg_end_of_loop ]]; then
_neg_to_be_added=$_neg_split_path[i]'/'
_neg_dyn_pwd=${_neg_dyn_pwd}${_neg_to_be_added}
else
_neg_to_be_added=${_neg_split_path[i]}
_neg_to_be_added=${_neg_to_be_added}"%F{4}/%F{7}"
# _neg_to_be_added=$_neg_to_be_added[1,1]'/'
_neg_dyn_pwd=${_neg_dyn_pwd}${_neg_to_be_added}
fi
done
unsetopt sh_word_split
IFS=${_neg_saveIFS}
[[ ${_neg_full_path/${HOME}/\~} != ${_neg_full_path} ]] && _neg_dyn_pwd=${_neg_dyn_pwd/\/~/~}
# remove the slash in front of ${HOME}
neg_prompt="%F${_neg_promptcolor}${_neg_dyn_pwd[0,-2]}%F{0}$_neg_user_token%b%k%f"
builtin print "${neg_user_pretok}%f%40<..<${neg_prompt}"
|
x
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 | #!/usr/bin/env python
# -*- coding: UTF-8 -*-
# Parse getopt-style help texts for options
# and generate zsh(1) completion function.
# http://github.com/RobSis/zsh-completion-generator
# Usage: program --help | ./help2comp.py program_name
import os
import sys
import re
import argparse
from string import Template
URL = 'http://github.com/RobSis/zsh-completion-generator'
STRIP_CHARS = " \t\n,="
COMPLETE_FUNCTION_TEMPLATE = """
#compdef $program_name
# zsh completions for '$program_name'
# automatically generated with $url
local arguments
arguments=(
$argument_list
'*:filename:_files'
)
_arguments -s $arguments
"""
ARGUMENT_TEMPLATE = """ {$opts}'[$description]$style'"""
SINGLE_ARGUMENT_TEMPLATE = """ '$opt[$description]$style'"""
def cut_option(line):
"""
Cuts out the first option (short or long) and its argument.
"""
# TODO: dare to make it regex-free?
newline = line.strip(STRIP_CHARS)
opt = re.findall(r'^(-[a-zA-Z0-9\-]+(?:[\[\ =][^\-\ ][a-zA-Z\<\>\[\|\:\]\-\_\?#]*\]?)?)', line)
if len(opt) > 0:
newline = line.replace(opt[0], "", 1).strip(STRIP_CHARS)
# return without parameter
return newline, re.split('[\ \[=]', opt[0])[0]
else:
return newline, None
def parse_options(help_text):
"""
Parses the options line by line.
When description is missing and options are missing on
consecutive line, link them together.
"""
all_options = []
previous_description_missing = False
for line in help_text:
line = line.strip(STRIP_CHARS)
if re.match(r'^--?[a-zA-Z0-9]+', line) != None: # starts with option
previous_description_missing = False
options = []
while True:
line, opt = cut_option(line)
if opt == None:
break
options.append(opt)
if (len(line) == 0):
previous_description_missing = True
options.append(line)
all_options.append(options)
elif previous_description_missing:
all_options[-1][-1] = line
previous_description_missing = False
return all_options
def _escape(line):
"""
Escape the syntax-breaking characters.
"""
line = line.replace('[','\[').replace(']','\]')
line = re.sub('\'', '', line) # ' is unescapable afaik
return line
def generate_argument_list(options):
"""
Generate list of arguments from the template.
"""
argument_list = []
for opts in options:
model = {}
# remove unescapable chars.
model['description'] = _escape(opts[-1])
model['style'] = ""
if (len(opts) > 2):
model['opts'] = ",".join(opts[:-1])
argument_list.append(Template(ARGUMENT_TEMPLATE).safe_substitute(model))
elif (len(opts) == 2):
model['opt'] = opts[0]
argument_list.append(Template(SINGLE_ARGUMENT_TEMPLATE).safe_substitute(model))
else:
pass
return "\n".join(argument_list)
def generate_completion_function(options, program_name):
"""
Generate completion function from the template.
"""
model = {}
model['program_name'] = program_name
model['argument_list'] = generate_argument_list(options)
model['url'] = URL
return Template(COMPLETE_FUNCTION_TEMPLATE).safe_substitute(model).strip()
if __name__ == "__main__":
if len(sys.argv) > 1:
options = parse_options(sys.stdin.readlines())
if (len(options) == 0):
sys.exit(2)
print(generate_completion_function(options, sys.argv[1]))
else:
print("Please specify program name.")
|
x
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 | #!/usr/bin/env zsh
# -------------------------------------------------------------------------------------------------
# Copyright (c) 2010-2017 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=grey}
: ${ZSH_HIGHLIGHT_STYLES[bracket-level-1]:=fg=24}
: ${ZSH_HIGHLIGHT_STYLES[bracket-level-2]:=fg=23}
: ${ZSH_HIGHLIGHT_STYLES[bracket-level-3]:=fg=25}
: ${ZSH_HIGHLIGHT_STYLES[bracket-level-4]:=fg=26}
: ${ZSH_HIGHLIGHT_STYLES[bracket-level-5]:=fg=30}
: ${ZSH_HIGHLIGHT_STYLES[bracket-level-6]:=fg=31}
: ${ZSH_HIGHLIGHT_STYLES[bracket-level-7]:=fg=32}
: ${ZSH_HIGHLIGHT_STYLES[bracket-level-8]:=fg=33}
: ${ZSH_HIGHLIGHT_STYLES[cursor-matchingbracket]:=standout}
# Whether the brackets highlighter should be called or not.
_zsh_highlight_highlighter_brackets_predicate()
{
[[ $WIDGET == zle-line-finish ]] || _zsh_highlight_cursor_moved || _zsh_highlight_buffer_modified
}
# Brackets highlighting function.
_zsh_highlight_highlighter_brackets_paint()
{
local char style
local -i bracket_color_size=${#ZSH_HIGHLIGHT_STYLES[(I)bracket-level-*]} buflen=${#BUFFER} level=0 matchingpos pos
local -A levelpos lastoflevel matching
# Find all brackets and remember which one is matching
for (( pos = 1; pos <= buflen; pos++ )) ; do
char=$BUFFER[pos]
case $char in
["([{"])
levelpos[$pos]=$((++level))
lastoflevel[$level]=$pos
;;
[")]}"])
if (( level > 0 )); then
matchingpos=$lastoflevel[$level]
levelpos[$pos]=$((level--))
if _zsh_highlight_brackets_match $matchingpos $pos; then
matching[$matchingpos]=$pos
matching[$pos]=$matchingpos
fi
else
levelpos[$pos]=-1
fi
;;
esac
done
# Now highlight all found brackets
for pos in ${(k)levelpos}; do
if (( $+matching[$pos] )); then
if (( bracket_color_size )); then
_zsh_highlight_add_highlight $((pos - 1)) $pos bracket-level-$(( (levelpos[$pos] - 1) % bracket_color_size + 1 ))
fi
else
_zsh_highlight_add_highlight $((pos - 1)) $pos bracket-error
fi
done
# If cursor is on a bracket, then highlight corresponding bracket, if any.
if [[ $WIDGET != zle-line-finish ]]; then
pos=$((CURSOR + 1))
if (( $+levelpos[$pos] )) && (( $+matching[$pos] )); then
local -i otherpos=$matching[$pos]
_zsh_highlight_add_highlight $((otherpos - 1)) $otherpos cursor-matchingbracket
fi
fi
}
# Helper function to differentiate type
_zsh_highlight_brackets_match()
{
case $BUFFER[$1] in
\() [[ $BUFFER[$2] == \) ]];;
\[) [[ $BUFFER[$2] == \] ]];;
\{) [[ $BUFFER[$2] == \} ]];;
*) false;;
esac
}
|
x
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | #!/bin/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_highlighter_cursor_predicate()
{
# remove cursor highlighting when the line is finished
[[ $WIDGET == zle-line-finish ]] || _zsh_highlight_cursor_moved
}
# Cursor highlighting function.
_zsh_highlight_highlighter_cursor_paint()
{
[[ $WIDGET == zle-line-finish ]] && return
_zsh_highlight_add_highlight $CURSOR $(( $CURSOR + 1 )) cursor
}
|
x
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 | ftype-exe fg=111
ftype-com fg=111
ftype-btm fg=111
ftype-bin fg=249
ftype-bat fg=108
ftype-cmd fg=108
ftype-7z fg=61,bold
ftype-ace fg=61,bold
ftype-alz fg=61,bold
ftype-arc fg=61
ftype-arj fg=61
ftype-bz fg=61,bold
ftype-bz2 fg=61,bold
ftype-cpio fg=61,bold
ftype-dz fg=61,bold
ftype-gz fg=61,bold
ftype-alp fg=61,bold
ftype-lha fg=61,bold
ftype-lrz fg=61,bold
ftype-lz fg=61,bold
ftype-lz4 fg=61,bold
ftype-lzh fg=61,bold
ftype-lzma fg=61,bold
ftype-rar fg=63
ftype-rz fg=61,bold
ftype-t7z fg=61,bold
ftype-tar fg=61
ftype-taz fg=61,bold
ftype-tbz fg=61,bold
ftype-tbz2 fg=61,bold
ftype-tgz fg=61,bold
ftype-tlz fg=61,bold
ftype-txz fg=61,bold
ftype-tz fg=61,bold
ftype-tzo fg=61,bold
ftype-xz fg=61,bold
ftype-z fg=61,bold
ftype-z fg=61,bold
ftype-Z fg=61,bold
ftype-Z fg=61,bold
ftype-zip fg=61,bold
ftype-ZIP fg=61,bold
ftype-zoo fg=61,bold
ftype-apk fg=68
ftype-cab fg=68
ftype-deb fg=68
ftype-egg fg=68
ftype-gem fg=68
ftype-jad fg=68
ftype-msi fg=68
ftype-pkg fg=68
ftype-rpm fg=68
ftype-udeb fg=68
ftype-xpi fg=68
ftype-arj fg=67
ftype-ear fg=67
ftype-jar fg=67
ftype-sar fg=67
ftype-war fg=67
ftype-qcow fg=61
ftype-qcow2 fg=61
ftype-vmdk fg=61
ftype-vdi fg=61
ftype-jpeg fg=24
ftype-jpg fg=24
ftype-JPG fg=24
ftype-bmp fg=110,bold
ftype-pbm fg=110
ftype-pgm fg=110
ftype-ppm fg=110
ftype-psd fg=110
ftype-indd fg=110
ftype-tga fg=110
ftype-xbm fg=111
ftype-xpm fg=36
ftype-tif fg=33
ftype-tiff fg=33
ftype-cgm fg=24,bold
ftype-CR2 fg=24,bold
ftype-dl fg=24
ftype-emf fg=24,bold
ftype-eps fg=24,bold
ftype-mng fg=24
ftype-pcx fg=24
ftype-png fg=24,bold
ftype-webp fg=24,bold
ftype-bpg fg=24,bold
ftype-svg fg=25
ftype-svgz fg=25
ftype-xcf fg=24,bold
ftype-xwd fg=24,bold
ftype-yuv fg=24,bold
ftype-gif fg=25,bold
ftype-icns fg=25,bold
ftype-ico fg=25,bold
ftype-aux fg=235,bold
ftype-bak fg=235,bold
ftype-bck fg=244
ftype-bbl fg=235,bold
ftype-blg fg=235,bold
ftype-cache fg=235,bold
ftype-class fg=235,bold
ftype-incomplete fg=235,bold
ftype-log fg=235,bold
ftype-o fg=235,bold
ftype-part fg=235,bold
ftype-pyc fg=235,bold
ftype-swp fg=235,bold
ftype-temp fg=244
ftype-tmp fg=244
ftype-added fg=235
ftype-chm fg=235
ftype-djv fg=7
ftype-djvu fg=7
ftype-dvi fg=235
ftype-epub fg=7
ftype-fb2 fg=7
ftype-lit fg=7
ftype-mobi fg=7
ftype-pdf fg=7,bold
ftype-cbz fg=7,bold
ftype-markdown fg=110
ftype-md fg=110
ftype-org fg=110
ftype-mf fg=110,italic
ftype-mkd fg=110
ftype-mfasl fg=73
ftype-txt fg=60
ftype-doc fg=30
ftype-docm fg=30
ftype-docx fg=30
ftype-dot fg=30
ftype-dotm fg=30
ftype-odm fg=30
ftype-odt fg=30
ftype-pages fg=30
ftype-rtf fg=30
ftype-gnumeric fg=14
ftype-xla fg=14
ftype-xls fg=14
ftype-xlsm fg=14
ftype-xlsx fg=14
ftype-chrt fg=14,bold
ftype-ppt fg=222
ftype-pptx fg=222
ftype-odb fg=29
ftype-odp fg=29
ftype-ods fg=29
ftype-db fg=99
ftype-ldf fg=99
ftype-mdb fg=99
ftype-mdf fg=99
ftype-odb fg=99
ftype-sql fg=99
ftype-sqlite fg=99
ftype-asm fg=228
ftype-asoundrc fg=6,italic
ftype-mutt fg=6,italic
ftype-awk fg=6,italic
ftype-coffee fg=6,italic
ftype-cs fg=6,italic
ftype-css fg=222
ftype-sass fg=222
ftype-scss fg=222
ftype-less fg=222
ftype-csv fg=6,italic
ftype-dir_colors fg=4,bold,italic
ftype-enc fg=6,italic
ftype-eps fg=7
ftype-eps2 fg=7
ftype-eps3 fg=7
ftype-epsf fg=7
ftype-epsi fg=7
ftype-ps fg=7
ftype-etx fg=6,italic
ftype-ex fg=6,italic
ftype-example fg=6,italic
ftype-fehbg fg=6,italic
ftype-fonts fg=6,italic
ftype-git fg=6,italic
ftype-gitignore fg=238
ftype-htm fg=77
ftype-html fg=77
ftype-jhtm fg=77,bold
ftype-hgrc fg=23,bold
ftype-hgignore fg=23,bold
ftype-hs fg=200
ftype-agda fg=200
ftype-htoprc fg=23,bold
ftype-info fg=23,bold
ftype-java fg=215,bold,underline
ftype-e fg=215,bold
ftype-js fg=200,bold,underline
ftype-jsm fg=68
ftype-jsp fg=68
ftype-lisp fg=68
ftype-scm fg=68
ftype-lam fg=68
ftype-lesshst fg=23,bold
ftype-log fg=23,bold
ftype-lua fg=24,underline
ftype-map fg=2,bold,italic
ftype-mf fg=2,bold,italic
ftype-mfasl fg=2,bold,italic
ftype-mi fg=2,bold,italic
ftype-msmtprc fg=2,bold,italic
ftype-mtx fg=2,bold,italic
ftype-muttrc fg=2,bold,italic
ftype-netrc fg=4,bold,italic
ftype-nfo fg=2,bold,italic
ftype-offlineimaprc fg=2,bold,italic
ftype-pacnew fg=33
ftype-patch bg=7,fg=16,bold
ftype-diff bg=7,fg=16,bold
ftype-pc fg=4,italic
ftype-pfa fg=4,italic
ftype-php fg=4,italic
ftype-pid fg=4,italic
ftype-pl fg=67
ftype-PL fg=67,bold
ftype-pm fg=4,italic
ftype-pod fg=23,bold
ftype-py fg=30,bold
ftype-rc fg=4,italic
ftype-erb fg=33,bold
ftype-irb fg=33,bold
ftype-rb fg=33,bold,underline
ftype-ru fg=4,italic
ftype-sed fg=4,italic
ftype-signature fg=4,italic
ftype-sty fg=5,bold,italic
ftype-sug fg=5,bold,italic
ftype-t fg=28,bold
ftype-tcl fg=225,underline
ftype-tk fg=225,underline
ftype-tdy fg=5,bold,italic
ftype-tfm fg=5,bold,italic
ftype-tfnt fg=5,bold,italic
ftype-theme fg=5,bold,italic
ftype-tdesktop-theme fg=5,bold,italic
ftype-tdesktop-pallete fg=5,bold,italic
ftype-attheme fg=5,italic
ftype-vim fg=221
ftype-viminfo fg=221
ftype-vimp fg=221
ftype-vimrc fg=221,underline
ftype-rasi fg=5,bold,italic
ftype-bash fg=103,bold
ftype-bash_history fg=103,bold
ftype-csh fg=103,bold
ftype-dash fg=103,bold
ftype-fish fg=103,bold
ftype-ksh fg=103,bold
ftype-sh fg=103,bold
ftype-sh* fg=103,bold
ftype-tcsh fg=103,bold
ftype-zsh fg=103,bold
ftype-bash_logout fg=77,bold,underline
ftype-bash_profile fg=77,bold,underline
ftype-profile fg=77,bold,underline
ftype-ttytterrc fg=5,bold,italic
ftype-urlview fg=5,bold,italic
ftype-Xauthority fg=4,bold,italic
ftype-xinitrc fg=4,bold,italic
ftype-Xmodmap fg=4,italic
ftype-Xresources fg=3,bold,italic
ftype-snippets fg=222
ftype-dmg fg=141,bold
ftype-img fg=141,bold
ftype-iso fg=141,bold
ftype-ISO fg=141,bold
ftype-mdf fg=141,bold
ftype-nrg fg=141,bold
ftype-vcd fg=141,bold
ftype-allow fg=24
ftype-deny fg=89
ftype-icls fg=60
ftype-jidgo fg=60
ftype-tex fg=73,bold,underline
ftype-latex fg=73,bold,underline
ftype-n3 fg=60
ftype-nfo fg=60
ftype-nt fg=60
ftype-owl fg=60
ftype-rc fg=60
ftype-rdf fg=60
ftype-aux fg=239
ftype-textile fg=60
ftype-torrent fg=60
ftype-ttl fg=60
ftype-xml fg=60
ftype-qml fg=60
ftype-yaml fg=60
ftype-cfg fg=77
ftype-conf fg=77
ftype-ovpn fg=77
ftype-nix fg=77
ftype-ini fg=77
ftype-toml fg=77
ftype-json fg=77,bold
ftype-yml fg=77
ftype-yml fg=77
ftype-reg fg=77
ftype-ffp fg=69
ftype-gpg fg=69
ftype-md5 fg=69
ftype-par fg=69
ftype-sfv fg=69
ftype-sha1 fg=69
ftype-st5 fg=69
ftype-alac fg=108,bold
ftype-flac fg=108,bold
ftype-dsf fg=108,bold
ftype-dff fg=108,bold
ftype-aiff fg=108,bold
ftype-ape fg=108,bold
ftype-aac fg=108
ftype-au fg=108
ftype-axa fg=108
ftype-m4a fg=108
ftype-m4b fg=108
ftype-m4r fg=108
ftype-mid fg=108
ftype-midi fg=108
ftype-mka fg=108
ftype-mp2 fg=108
ftype-mp3 fg=108
ftype-mpc fg=108
ftype-oga fg=108
ftype-ogg fg=108
ftype-ra fg=108
ftype-spx fg=108
ftype-wav fg=108,bold
ftype-wma fg=108
ftype-cue fg=28
ftype-m3u fg=28
ftype-m3u8 fg=28
ftype-pls fg=28
ftype-xspf fg=28
ftype-dat fg=5
ftype-fcm fg=5
ftype-m4 fg=5,italic
ftype-mod fg=5
ftype-oga fg=5
ftype-s3m fg=5,bold
ftype-S3M fg=5,bold
ftype-sid fg=5,bold
ftype-spl fg=5
ftype-wv fg=5
ftype-wvc fg=5
ftype-asf fg=12,bold
ftype-avi fg=12,bold
ftype-AVI fg=12,bold
ftype-divx fg=12,bold
ftype-flc fg=12,bold
ftype-fli fg=12,bold
ftype-flv fg=12,bold
ftype-gl fg=12,bold
ftype-m2ts fg=12,bold
ftype-m2v fg=12,bold
ftype-m4v fg=12,bold
ftype-mkv fg=12,bold
ftype-mov fg=12,bold
ftype-MOV fg=12,bold
ftype-mp4 fg=12,bold
ftype-mp4v fg=12,bold
ftype-mpeg fg=12,bold
ftype-mpg fg=12,bold
ftype-nuv fg=12,bold
ftype-ogm fg=12,bold
ftype-ogv fg=12,bold
ftype-qt fg=12,bold
ftype-rm fg=12,bold
ftype-rmvb fg=12,bold
ftype-sample fg=12,bold
ftype-ts fg=12
ftype-vob fg=12,bold
ftype-VOB fg=12,bold
ftype-webm fg=12,bold
ftype-wmv fg=12,bold
ftype-anx fg=13,bold
ftype-axv fg=13,bold
ftype-ogx fg=13,bold
ftype-ass fg=116,bold
ftype-srt fg=116,bold
ftype-bdf fg=61
ftype-dfont fg=61,bold
ftype-fon fg=61,bold
ftype-gsf fg=61
ftype-otf fg=61,bold
ftype-pcf fg=61
ftype-pfa fg=61
ftype-pfb fg=61
ftype-ttf fg=61,bold
ftype-adf fg=35
ftype-fm2 fg=35
ftype-32x fg=232
ftype-a00 fg=232
ftype-a52 fg=232
ftype-a64 fg=232
ftype-A64 fg=232
ftype-a78 fg=232
ftype-atr fg=232
ftype-cdi fg=232
ftype-gb fg=232
ftype-gba fg=232
ftype-gbc fg=232
ftype-gel fg=232
ftype-gg fg=232
ftype-ggl fg=232
ftype-j64 fg=232
ftype-nds fg=232
ftype-nes fg=232
ftype-rom fg=232,bold
ftype-sav fg=232
ftype-sms fg=33
ftype-desktop fg=250
ftype-automount fg=66
ftype-device fg=24
ftype-mount fg=66
ftype-path fg=66
ftype-service fg=81
ftype-snapshot fg=97
ftype-socket fg=75
ftype-swap fg=97
ftype-target fg=73
ftype-timer fg=111
ftype-c fg=110,bold
ftype-c++ fg=24,bold,underline
ftype-C fg=24,bold,underline
ftype-cc fg=24,bold,underline
ftype-cp fg=24,bold,underline
ftype-cpp fg=24,bold,underline
ftype-cs fg=74,bold,underline
ftype-cxx fg=24,bold,underline
ftype-erl fg=227,underline
ftype-go fg=227,underline
ftype-ii fg=24,bold,underline
ftype-ml fg=227,underline
ftype-rs fg=67,underline
ftype-rst fg=67,underline
ftype-swift fg=67,underline
ftype-pas fg=67,underline
ftype-scala fg=227,underline
ftype-clj fg=228,underline
ftype-el fg=228,underline
ftype-f fg=29
ftype-for fg=29
ftype-ftn fg=29
ftype-h fg=29
ftype-h++ fg=29
ftype-H fg=29
ftype-hh fg=29
ftype-hpp fg=29
ftype-hxx fg=29
ftype-s fg=29
ftype-S fg=29
ftype-sx fg=29
ftype-tcc fg=29
ftype-am fg=235
ftype-in fg=235
ftype-old fg=235
ftype-cap fg=29
ftype-dmp fg=29
ftype-dump fg=99
ftype-pcap fg=29
ftype-am fg=235
ftype-in fg=235
ftype-old fg=235
|
x
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | # -------------------------------------------------------------------------------------------------
# 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[line]:=}
# Whether the root highlighter should be called or not.
_zsh_highlight_highlighter_line_predicate()
{
_zsh_highlight_buffer_modified
}
# root highlighting function.
_zsh_highlight_highlighter_line_paint()
{
_zsh_highlight_add_highlight 0 $#BUFFER line
}
|
x
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 | #!/bin/zsh
ZSH_HIGHLIGHT_STYLES+=(
default none
unknown-token none
suffix-alias fg=green,underline
reserved-word fg=004
alias fg=green
builtin fg=green
function fg=green,underline
command fg=green
precommand fg=green,underline
path fg=white
path_prefix none
path_approx fg=white
# path_pathseparator
# path_prefix_pathseparator
hashed-command fg=green
globbing fg=110
history-expansion fg=blue
single-hyphen-option fg=244
double-hyphen-option fg=244
comment fg=221
arg0 fg=green
rc-quote cyan
# redirection none
# commandseparator none
back-quoted-argument fg=024,bold
single-quoted-argument fg=024
double-quoted-argument fg=024
dollar-double-quoted-argument fg=004,bold
back-double-quoted-argument fg=024,bold
back-dollar-quoted-argument fg=024,bold
assign fg=222,bold
)
ZSH_HIGHLIGHT_STYLES+=($(< ${ZDOTDIR}/highlighters/ft_list.zsh))
# Whether the highlighter should be called or not.
_zsh_highlight_highlighter_main_predicate()
{
# may need to remove path_prefix highlighting when the line ends
[[ $WIDGET == zle-line-finish ]] || _zsh_highlight_buffer_modified
}
# Helper to deal with tokens crossing line boundaries.
_zsh_highlight_main_add_region_highlight() {
integer start=$1 end=$2
shift 2
if (( $+argv[2] )); then
# Caller specified inheritance explicitly.
else
# Automate inheritance.
typeset -A fallback_of; fallback_of=(
alias arg0
suffix-alias arg0
builtin arg0
function arg0
command arg0
precommand arg0
hashed-command arg0
path_prefix path
# The path separator fallback won't ever be used, due to the optimisation
# in _zsh_highlight_main_highlighter_highlight_path_separators().
path_pathseparator path
path_prefix_pathseparator path_prefix
single-quoted-argument{-unclosed,}
double-quoted-argument{-unclosed,}
dollar-single-quoted-argument{-unclosed,}
back-quoted-argument{-unclosed,}
)
local needle=$1 value
while [[ -n ${value::=$fallback_of[$needle]} ]]; do
unset "fallback_of[$needle]" # paranoia against infinite loops
argv+=($value)
needle=$value
done
fi
# The calculation was relative to $PREBUFFER$BUFFER, but region_highlight is
# relative to $BUFFER.
(( start -= $#PREBUFFER ))
(( end -= $#PREBUFFER ))
(( start >= end )) && { print -r -- >&2 "zsh-syntax-highlighting: BUG: _zsh_highlight_main_add_region_highlight: start($start) >= end($end)"; return }
(( end <= 0 )) && return
(( start < 0 )) && start=0 # having start<0 is normal with e.g. multiline strings
_zsh_highlight_add_highlight $start $end "$@"
}
_zsh_highlight_main_add_many_region_highlights() {
for 1 2 3; do
_zsh_highlight_main_add_region_highlight $1 $2 $3
done
}
# Get the type of a command.
#
# Uses the zsh/parameter module if available to avoid forks, and a
# wrapper around 'type -w' as fallback.
#
# Takes a single argument.
#
# The result will be stored in REPLY.
_zsh_highlight_main__type() {
if (( $+_zsh_highlight_main__command_type_cache )); then
REPLY=$_zsh_highlight_main__command_type_cache[(e)$1]
if [[ -n "$REPLY" ]]; then
return
fi
fi
if (( $#options_to_set )); then
setopt localoptions $options_to_set;
fi
unset REPLY
if zmodload -e zsh/parameter; then
if (( $+aliases[(e)$1] )); then
REPLY=alias
elif (( $+saliases[(e)${1##*.}] )); then
REPLY='suffix alias'
elif (( $reswords[(Ie)$1] )); then
REPLY=reserved
elif (( $+functions[(e)$1] )); then
REPLY=function
elif (( $+builtins[(e)$1] )); then
REPLY=builtin
elif (( $+commands[(e)$1] )); then
REPLY=command
# zsh 5.2 and older have a bug whereby running 'type -w ./sudo' implicitly
# runs 'hash ./sudo=/usr/local/bin/./sudo' (assuming /usr/local/bin/sudo
# exists and is in $PATH). Avoid triggering the bug, at the expense of
# falling through to the $() below, incurring a fork. (Issue #354.)
#
# The first disjunct mimics the isrelative() C call from the zsh bug.
elif { [[ $1 != */* ]] || is-at-least 5.3 } &&
! builtin type -w -- $1 >/dev/null 2>&1; then
REPLY=none
fi
fi
if ! (( $+REPLY )); then
# Note that 'type -w' will run 'rehash' implicitly.
REPLY="${$(LC_ALL=C builtin type -w -- $1 2>/dev/null)##*: }"
fi
if (( $+_zsh_highlight_main__command_type_cache )); then
_zsh_highlight_main__command_type_cache[(e)$1]=$REPLY
fi
}
# Check whether the first argument is a redirection operator token.
# Report result via the exit code.
_zsh_highlight_main__is_redirection() {
# A redirection operator token:
# - starts with an optional single-digit number;
# - then, has a '<' or '>' character;
# - is not a process substitution [<(...) or >(...)].
# - is not a numeric glob <->
[[ $1 == (<0-9>|)(\<|\>)* ]] && [[ $1 != (\<|\>)$'\x28'* ]] && [[ $1 != *'<'*'-'*'>'* ]]
}
# Resolve alias.
#
# Takes a single argument.
#
# The result will be stored in REPLY.
_zsh_highlight_main__resolve_alias() {
if zmodload -e zsh/parameter; then
REPLY=${aliases[$arg]}
else
REPLY="${"$(alias -- $arg)"#*=}"
fi
}
# Check that the top of $braces_stack has the expected value. If it does, set
# the style according to $2; otherwise, set style=unknown-token.
#
# $1: character expected to be at the top of $braces_stack
# $2: assignment to execute it if matches
_zsh_highlight_main__stack_pop() {
if [[ $braces_stack[1] == $1 ]]; then
braces_stack=${braces_stack:1}
eval "$2"
else
style=unknown-token
fi
}
# Main syntax highlighting function.
_zsh_highlight_highlighter_main_paint()
{
setopt localoptions extendedglob
# At the PS3 prompt and in vared, highlight nothing.
#
# (We can't check this in _zsh_highlight_highlighter_main_predicate because
# if the predicate returns false, the previous value of region_highlight
# would be reused.)
if [[ $CONTEXT == (select|vared) ]]; then
return
fi
## Variable declarations and initializations
local start_pos=0 end_pos highlight_glob=true arg style
local in_array_assignment=false # true between 'a=(' and the matching ')'
typeset -a ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR
typeset -a ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS
typeset -a ZSH_HIGHLIGHT_TOKENS_CONTROL_FLOW
local -a options_to_set # used in callees
local buf="$PREBUFFER$BUFFER"
integer len="${#buf}"
integer pure_buf_len=$(( len - ${#PREBUFFER} )) # == $#BUFFER, used e.g. in *_check_path
# "R" for round
# "Q" for square
# "Y" for curly
# "D" for do/done
# "$" for 'end' (matches 'foreach' always; also used with cshjunkiequotes in repeat/while)
# "?" for 'if'/'fi'; also checked by 'elif'/'else'
# ":" for 'then'
local braces_stack
if [[ $zsyh_user_options[ignorebraces] == on || ${zsyh_user_options[ignoreclosebraces]:-off} == on ]]; then
local right_brace_is_recognised_everywhere=false
else
local right_brace_is_recognised_everywhere=true
fi
if [[ $zsyh_user_options[pathdirs] == on ]]; then
options_to_set+=( PATH_DIRS )
fi
ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR=(
'|' '||' ';' '&' '&&'
'|&'
'&!' '&|'
# ### 'case' syntax, but followed by a pattern, not by a command
';;' ';&' ';|'
)
ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS=(
'builtin' 'command' 'exec' 'nocorrect' 'noglob' 'sudo' 's'
'pkexec' # immune to #121 because it's usually not passed --option flags
)
# Tokens that, at (naively-determined) "command position", are followed by
# a de jure command position. All of these are reserved words.
ZSH_HIGHLIGHT_TOKENS_CONTROL_FLOW=(
$'\x7b' # block
$'\x28' # subshell
'()' # anonymous function
'while'
'until'
'if'
'then'
'elif'
'else'
'do'
'time'
'coproc'
'!' # reserved word; unrelated to $histchars[1]
)
local -a match mbegin mend
# State machine
#
# The states are:
# - :start: Command word
# - :sudo_opt: A leading-dash option to sudo (such as "-u" or "-i")
# - :sudo_arg: The argument to a sudo leading-dash option that takes one,
# when given as a separate word; i.e., "foo" in "-u foo" (two
# words) but not in "-ufoo" (one word).
# - :regular: "Not a command word", and command delimiters are permitted.
# Mainly used to detect premature termination of commands.
# - :always: The word 'always' in the «{ foo } always { bar }» syntax.
#
# When the kind of a word is not yet known, $this_word / $next_word may contain
# multiple states. For example, after "sudo -i", the next word may be either
# another --flag or a command name, hence the state would include both :start:
# and :sudo_opt:.
#
# The tokens are always added with both leading and trailing colons to serve as
# word delimiters (an improvised array); [[ $x == *:foo:* ]] and x=${x//:foo:/}
# will DTRT regardless of how many elements or repetitions $x has..
#
# Handling of redirections: upon seeing a redirection token, we must stall
# the current state --- that is, the value of $this_word --- for two iterations
# (one for the redirection operator, one for the word following it representing
# the redirection target). Therefore, we set $in_redirection to 2 upon seeing a
# redirection operator, decrement it each iteration, and stall the current state
# when it is non-zero. Thus, upon reaching the next word (the one that follows
# the redirection operator and target), $this_word will still contain values
# appropriate for the word immediately following the word that preceded the
# redirection operator.
#
# The "the previous word was a redirection operator" state is not communicated
# to the next iteration via $next_word/$this_word as usual, but via
# $in_redirection. The value of $next_word from the iteration that processed
# the operator is discarded.
#
local this_word=':start:' next_word
integer in_redirection
# Processing buffer
local proc_buf="$buf"
local -a args
if [[ $zsyh_user_options[interactivecomments] == on ]]; then
args=(${(zZ+c+)buf})
else
args=(${(z)buf})
fi
for arg in $args; do
# Initialize $next_word.
if (( in_redirection )); then
(( --in_redirection ))
fi
if (( in_redirection == 0 )); then
# Initialize $next_word to its default value.
next_word=':regular:'
else
# Stall $next_word.
fi
# Initialize per-"simple command" [zshmisc(1)] variables:
#
# $already_added (see next paragraph)
# $style how to highlight $arg
# $in_array_assignment boolean flag for "between '(' and ')' of array assignment"
# $highlight_glob boolean flag for "'noglob' is in effect"
#
# $already_added is set to 1 to disable adding an entry to region_highlight
# for this iteration. Currently, that is done for "" and $'' strings,
# which add the entry early so escape sequences within the string override
# the string's color.
integer already_added=0
style=unknown-token
if [[ $this_word == *':start:'* ]]; then
in_array_assignment=false
if [[ $arg == 'noglob' ]]; then
highlight_glob=false
fi
fi
# Compute the new $start_pos and $end_pos, skipping over whitespace in $buf.
if [[ $arg == ';' ]] ; then
# We're looking for either a semicolon or a newline, whichever comes
# first. Both of these are rendered as a ";" (SEPER) by the ${(z)..}
# flag.
#
# We can't use the (Z+n+) flag because that elides the end-of-command
# token altogether, so 'echo foo\necho bar' (two commands) becomes
# indistinguishable from 'echo foo echo bar' (one command with three
# words for arguments).
local needle=$'[;\n]'
integer offset=$(( ${proc_buf[(i)$needle]} - 1 ))
(( start_pos += offset ))
(( end_pos = start_pos + $#arg ))
else
# The line was:
#
# integer offset=$(((len-start_pos)-${#${proc_buf##([[:space:]]|\\[[:space:]])#}}))
#
# - len-start_pos is length of current proc_buf; basically: initial length minus where
# we are, and proc_buf is chopped to the "where we are" (compare the "previous value
# of start_pos" below, and the len-(start_pos-offset) = len-start_pos+offset)
# - what's after main minus sign is: length of proc_buf without spaces at the beginning
# - so what the line actually did, was computing length of the spaces!
# - this can be done via (#b) flag, like below
if [[ "$proc_buf" = (#b)(#s)(([[:space:]]|\\[[:space:]])##)* ]]; then
# The first, outer parenthesis
integer offset="${#match[1]}"
else
integer offset=0
fi
((start_pos+=offset))
((end_pos=$start_pos+${#arg}))
fi
# Compute the new $proc_buf. We advance it
# (chop off characters from the beginning)
# beyond what end_pos points to, by skipping
# as many characters as end_pos was advanced.
#
# end_pos was advanced by $offset (via start_pos)
# and by $#arg. Note the `start_pos=$end_pos`
# below.
#
# As for the [,len]. We could use [,len-start_pos+offset]
# here, but to make it easier on eyes, we use len and
# rely on the fact that Zsh simply handles that. The
# length of proc_buf is len-start_pos+offset because
# we're chopping it to match current start_pos, so its
# length matches the previous value of start_pos.
#
# Why [,-1] is slower than [,length] isn't clear.
proc_buf="${proc_buf[offset + $#arg + 1,len]}"
# Handle the INTERACTIVE_COMMENTS option.
#
# We use the (Z+c+) flag so the entire comment is presented as one token in $arg.
if [[ $zsyh_user_options[interactivecomments] == on && $arg[1] == $histchars[3] ]]; then
if [[ $this_word == *(':regular:'|':start:')* ]]; then
style=comment
else
style=unknown-token # prematurely terminated
fi
_zsh_highlight_main_add_region_highlight $start_pos $end_pos $style
already_added=1
start_pos=$end_pos
continue
fi
# Analyse the current word.
if _zsh_highlight_main__is_redirection $arg ; then
if (( in_redirection )); then
_zsh_highlight_main_add_region_highlight $start_pos $end_pos unknown-token
already_added=1
else
in_redirection=2
fi
fi
# Special-case the first word after 'sudo'.
if (( ! in_redirection )); then
if [[ $this_word == *':sudo_opt:'* ]] && [[ $arg != -* ]]; then
this_word=${this_word//:sudo_opt:/}
fi
fi
# Parse the sudo command line
if (( ! in_redirection )); then
if [[ $this_word == *':sudo_opt:'* ]]; then
case "$arg" in
# Flag that requires an argument
'-'[Cgprtu]) this_word=${this_word//:start:/};
next_word=':sudo_arg:';;
# This prevents misbehavior with sudo -u -otherargument
'-'*) this_word=${this_word//:start:/};
next_word+=':start:';
next_word+=':sudo_opt:';;
*) ;;
esac
elif [[ $this_word == *':sudo_arg:'* ]]; then
next_word+=':sudo_opt:'
next_word+=':start:'
fi
fi
# The Great Fork: is this a command word? Is this a non-command word?
if [[ $this_word == *':always:'* && $arg == 'always' ]]; then
# try-always construct
style=reserved-word # de facto a reserved word, although not de jure
next_word=':start:'
elif [[ $this_word == *':start:'* ]] && (( in_redirection == 0 )); then # $arg is the command word
if [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS:#"$arg"} ]]; then
style=precommand
elif [[ "$arg" = "sudo" ]] && { _zsh_highlight_main__type sudo; [[ -n $REPLY && $REPLY != "none" ]] }; then
style=precommand
next_word=${next_word//:regular:/}
next_word+=':sudo_opt:'
next_word+=':start:'
else
_zsh_highlight_main_highlighter_expand_path $arg
local expanded_arg="$REPLY"
_zsh_highlight_main__type ${expanded_arg}
local res="$REPLY"
() {
# Special-case: command word is '$foo', like that, without braces or anything.
#
# That's not entirely correct --- if the parameter's value happens to be a reserved
# word, the parameter expansion will be highlighted as a reserved word --- but that
# incorrectness is outweighed by the usability improvement of permitting the use of
# parameters that refer to commands, functions, and builtins.
local -a match mbegin mend
local MATCH; integer MBEGIN MEND
if [[ $res == none ]] && (( ${+parameters} )) &&
[[ ${arg[1]} == \$ ]] && [[ ${arg:1} =~ ^([A-Za-z_][A-Za-z0-9_]*|[0-9]+)$ ]] &&
(( ${+parameters[(e)${MATCH}]} )) && [[ ${parameters[(e)$MATCH]} != *special* ]]
then
_zsh_highlight_main__type ${(P)MATCH}
res=$REPLY
fi
}
case $res in
reserved) # reserved word
style=reserved-word
#
# Match braces.
case $arg in
($'\x7b')
braces_stack='Y'"$braces_stack"
;;
($'\x7d')
# We're at command word, so no need to check $right_brace_is_recognised_everywhere
_zsh_highlight_main__stack_pop 'Y' style=reserved-word
if [[ $style == reserved-word ]]; then
next_word+=':always:'
fi
;;
('do')
braces_stack='D'"$braces_stack"
;;
('done')
_zsh_highlight_main__stack_pop 'D' style=reserved-word
;;
('if')
braces_stack=':?'"$braces_stack"
;;
('then')
_zsh_highlight_main__stack_pop ':' style=reserved-word
;;
('elif')
if [[ ${braces_stack[1]} == '?' ]]; then
braces_stack=':'"$braces_stack"
else
style=unknown-token
fi
;;
('else')
if [[ ${braces_stack[1]} == '?' ]]; then
:
else
style=unknown-token
fi
;;
('fi')
_zsh_highlight_main__stack_pop '?' ""
;;
('foreach')
braces_stack='$'"$braces_stack"
;;
('end')
_zsh_highlight_main__stack_pop '$' style=reserved-word
;;
esac
;;
'suffix alias') style=suffix-alias;;
alias) () {
integer insane_alias
case $arg in
# Issue #263: aliases with '=' on their LHS.
#
# There are three cases:
#
# - Unsupported, breaks 'alias -L' output, but invokable:
('='*) :;;
# - Unsupported, not invokable:
(*'='*) insane_alias=1;;
# - The common case:
(*) :;;
esac
if (( insane_alias )); then
style=unknown-token
else
# The common case.
style=alias
_zsh_highlight_main__resolve_alias $arg
local alias_target="$REPLY"
[[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS:#"$alias_target"} && -z ${(M)ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS:#"$arg"} ]] && ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS+=($arg)
fi
}
;;
builtin) style=builtin;;
function) style=function;;
command) style=command;;
hashed) style=hashed-command;;
none) if _zsh_highlight_main_highlighter_check_assign; then
style=assign
if [[ $arg[-1] == '(' ]]; then
in_array_assignment=true
else
# assignment to a scalar parameter.
# (For array assignments, the command doesn't start until the ")" token.)
next_word+=':start:'
fi
elif [[ $arg[0,1] = $histchars[0,1] ]] && (( $#arg[0,2] == 2 )); then
style=history-expansion
elif [[ $arg[0,1] == $histchars[2,2] ]]; then
style=history-expansion
elif [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR:#"$arg"} ]]; then
if [[ $this_word == *':regular:'* ]]; then
# This highlights empty commands (semicolon follows nothing) as an error.
# Zsh accepts them, though.
style=commandseparator
else
style=unknown-token
fi
elif (( in_redirection == 2 )); then
style=redirection
elif [[ $arg[1,2] == '((' ]]; then
# Arithmetic evaluation.
#
# Note: prior to zsh-5.1.1-52-g4bed2cf (workers/36669), the ${(z)...}
# splitter would only output the '((' token if the matching '))' had
# been typed. Therefore, under those versions of zsh, BUFFER="(( 42"
# would be highlighted as an error until the matching "))" are typed.
#
# We highlight just the opening parentheses, as a reserved word; this
# is how [[ ... ]] is highlighted, too.
style=reserved-word
_zsh_highlight_main_add_region_highlight $start_pos $((start_pos + 2)) $style
already_added=1
if [[ $arg[-2,-1] == '))' ]]; then
_zsh_highlight_main_add_region_highlight $((end_pos - 2)) $end_pos $style
already_added=1
fi
elif [[ $arg == '()' ]]; then
# anonymous function
style=reserved-word
elif [[ $arg == $'\x28' ]]; then
# subshell
style=reserved-word
braces_stack='R'"$braces_stack"
elif [[ $arg == $'\x29' ]]; then
# end of subshell
_zsh_highlight_main__stack_pop 'R' style=reserved-word
else
if _zsh_highlight_main_highlighter_check_path; then
style=$REPLY
else
style=unknown-token
fi
fi
;;
*) _zsh_highlight_main_add_region_highlight $start_pos $end_pos arg0_$res arg0
already_added=1
;;
esac
fi
fi
if (( ! already_added )) && [[ $style == unknown-token ]] && # not handled by the 'command word' codepath
{ (( in_redirection )) || [[ $this_word == *':regular:'* ]] || [[ $this_word == *':sudo_opt:'* ]] || [[ $this_word == *':sudo_arg:'* ]] }
then # $arg is a non-command word
case $arg in
$'\x29') # subshell or end of array assignment
if $in_array_assignment; then
style=assign
in_array_assignment=false
next_word+=':start:'
else
_zsh_highlight_main__stack_pop 'R' style=reserved-word
fi;;
$'\x28\x29') # possibly a function definition
if [[ $zsyh_user_options[multifuncdef] == on ]] || false # TODO: or if the previous word was a command word
then
next_word+=':start:'
fi
style=reserved-word
;;
#--[ Begining of ftype array ]------@@@@
*.old) style=ftype-old ;;
*.in) style=ftype-in ;;
*.am) style=ftype-am ;;
*.pcap) style=ftype-pcap ;;
*.dump) style=ftype-dump ;;
*.dmp) style=ftype-dmp ;;
*.cap) style=ftype-cap ;;
*.old) style=ftype-old ;;
*.in) style=ftype-in ;;
*.am) style=ftype-am ;;
*.tcc) style=ftype-tcc ;;
*.sx) style=ftype-sx ;;
*.S) style=ftype-S ;;
*.s) style=ftype-s ;;
*.hxx) style=ftype-hxx ;;
*.hpp) style=ftype-hpp ;;
*.hh) style=ftype-hh ;;
*.H) style=ftype-H ;;
*.h++) style=ftype-h++ ;;
*.h) style=ftype-h ;;
*.ftn) style=ftype-ftn ;;
*.for) style=ftype-for ;;
*.f) style=ftype-f ;;
*.el) style=ftype-el ;;
*.clj) style=ftype-clj ;;
*.scala) style=ftype-scala ;;
*.pas) style=ftype-pas ;;
*.swift) style=ftype-swift ;;
*.rst) style=ftype-rst ;;
*.rs) style=ftype-rs ;;
*.ml) style=ftype-ml ;;
*.ii) style=ftype-ii ;;
*.go) style=ftype-go ;;
*.erl) style=ftype-erl ;;
*.cxx) style=ftype-cxx ;;
*.cs) style=ftype-cs ;;
*.cpp) style=ftype-cpp ;;
*.cp) style=ftype-cp ;;
*.cc) style=ftype-cc ;;
*.C) style=ftype-C ;;
*.c++) style=ftype-c++ ;;
*.c) style=ftype-c ;;
*.timer) style=ftype-timer ;;
*.target) style=ftype-target ;;
*.swap) style=ftype-swap ;;
*.socket) style=ftype-socket ;;
*.snapshot) style=ftype-snapshot ;;
*.service) style=ftype-service ;;
*.path) style=ftype-path ;;
*.mount) style=ftype-mount ;;
*.device) style=ftype-device ;;
*.automount) style=ftype-automount ;;
*.desktop) style=ftype-desktop ;;
*.sms) style=ftype-sms ;;
*.sav) style=ftype-sav ;;
*.rom) style=ftype-rom ;;
*.nes) style=ftype-nes ;;
*.nds) style=ftype-nds ;;
*.j64) style=ftype-j64 ;;
*.ggl) style=ftype-ggl ;;
*.gg) style=ftype-gg ;;
*.gel) style=ftype-gel ;;
*.gbc) style=ftype-gbc ;;
*.gba) style=ftype-gba ;;
*.gb) style=ftype-gb ;;
*.cdi) style=ftype-cdi ;;
*.atr) style=ftype-atr ;;
*.a78) style=ftype-a78 ;;
*.A64) style=ftype-A64 ;;
*.a64) style=ftype-a64 ;;
*.a52) style=ftype-a52 ;;
*.a00) style=ftype-a00 ;;
*.32x) style=ftype-32x ;;
*.fm2) style=ftype-fm2 ;;
*.adf) style=ftype-adf ;;
*.ttf) style=ftype-ttf ;;
*.pfb) style=ftype-pfb ;;
*.pfa) style=ftype-pfa ;;
*.pcf) style=ftype-pcf ;;
*.otf) style=ftype-otf ;;
*.gsf) style=ftype-gsf ;;
*.fon) style=ftype-fon ;;
*.dfont) style=ftype-dfont ;;
*.bdf) style=ftype-bdf ;;
*.srt) style=ftype-srt ;;
*.ass) style=ftype-ass ;;
*.ogx) style=ftype-ogx ;;
*.axv) style=ftype-axv ;;
*.anx) style=ftype-anx ;;
*.wmv) style=ftype-wmv ;;
*.webm) style=ftype-webm ;;
*.VOB) style=ftype-VOB ;;
*.vob) style=ftype-vob ;;
*.ts) style=ftype-ts ;;
*.sample) style=ftype-sample ;;
*.rmvb) style=ftype-rmvb ;;
*.rm) style=ftype-rm ;;
*.qt) style=ftype-qt ;;
*.ogv) style=ftype-ogv ;;
*.ogm) style=ftype-ogm ;;
*.nuv) style=ftype-nuv ;;
*.mpg) style=ftype-mpg ;;
*.mpeg) style=ftype-mpeg ;;
*.mp4v) style=ftype-mp4v ;;
*.mp4) style=ftype-mp4 ;;
*.MOV) style=ftype-MOV ;;
*.mov) style=ftype-mov ;;
*.mkv) style=ftype-mkv ;;
*.m4v) style=ftype-m4v ;;
*.m2v) style=ftype-m2v ;;
*.m2ts) style=ftype-m2ts ;;
*.gl) style=ftype-gl ;;
*.flv) style=ftype-flv ;;
*.fli) style=ftype-fli ;;
*.flc) style=ftype-flc ;;
*.divx) style=ftype-divx ;;
*.AVI) style=ftype-AVI ;;
*.avi) style=ftype-avi ;;
*.asf) style=ftype-asf ;;
*.wvc) style=ftype-wvc ;;
*.wv) style=ftype-wv ;;
*.spl) style=ftype-spl ;;
*.sid) style=ftype-sid ;;
*.S3M) style=ftype-S3M ;;
*.s3m) style=ftype-s3m ;;
*.oga) style=ftype-oga ;;
*.mod) style=ftype-mod ;;
*.m4) style=ftype-m4 ;;
*.fcm) style=ftype-fcm ;;
*.dat) style=ftype-dat ;;
*.xspf) style=ftype-xspf ;;
*.pls) style=ftype-pls ;;
*.m3u8) style=ftype-m3u8 ;;
*.m3u) style=ftype-m3u ;;
*.cue) style=ftype-cue ;;
*.wma) style=ftype-wma ;;
*.wav) style=ftype-wav ;;
*.spx) style=ftype-spx ;;
*.ra) style=ftype-ra ;;
*.ogg) style=ftype-ogg ;;
*.oga) style=ftype-oga ;;
*.mpc) style=ftype-mpc ;;
*.mp3) style=ftype-mp3 ;;
*.mp2) style=ftype-mp2 ;;
*.mka) style=ftype-mka ;;
*.midi) style=ftype-midi ;;
*.mid) style=ftype-mid ;;
*.m4r) style=ftype-m4r ;;
*.m4b) style=ftype-m4b ;;
*.m4a) style=ftype-m4a ;;
*.axa) style=ftype-axa ;;
*.au) style=ftype-au ;;
*.aac) style=ftype-aac ;;
*.ape) style=ftype-ape ;;
*.aiff) style=ftype-aiff ;;
*.dff) style=ftype-dff ;;
*.dsf) style=ftype-dsf ;;
*.flac) style=ftype-flac ;;
*.alac) style=ftype-alac ;;
*.st5) style=ftype-st5 ;;
*.sha1) style=ftype-sha1 ;;
*.sfv) style=ftype-sfv ;;
*.par) style=ftype-par ;;
*.md5) style=ftype-md5 ;;
*.gpg) style=ftype-gpg ;;
*.ffp) style=ftype-ffp ;;
*.reg) style=ftype-reg ;;
*.yml) style=ftype-yml ;;
*.yml) style=ftype-yml ;;
*.json) style=ftype-json ;;
*.toml) style=ftype-toml ;;
*.ini) style=ftype-ini ;;
*.nix) style=ftype-nix ;;
*.ovpn) style=ftype-ovpn ;;
*.conf) style=ftype-conf ;;
*.cfg) style=ftype-cfg ;;
*.yaml) style=ftype-yaml ;;
*.qml) style=ftype-qml ;;
*.xml) style=ftype-xml ;;
*.ttl) style=ftype-ttl ;;
*.torrent) style=ftype-torrent ;;
*.textile) style=ftype-textile ;;
*.aux) style=ftype-aux ;;
*.rdf) style=ftype-rdf ;;
*.rc) style=ftype-rc ;;
*.owl) style=ftype-owl ;;
*.nt) style=ftype-nt ;;
*.nfo) style=ftype-nfo ;;
*.n3) style=ftype-n3 ;;
*.latex) style=ftype-latex ;;
*.tex) style=ftype-tex ;;
*.jidgo) style=ftype-jidgo ;;
*.icls) style=ftype-icls ;;
*.deny) style=ftype-deny ;;
*.allow) style=ftype-allow ;;
*.vcd) style=ftype-vcd ;;
*.nrg) style=ftype-nrg ;;
*.mdf) style=ftype-mdf ;;
*.ISO) style=ftype-ISO ;;
*.iso) style=ftype-iso ;;
*.img) style=ftype-img ;;
*.dmg) style=ftype-dmg ;;
*.snippets) style=ftype-snippets ;;
*.Xresources) style=ftype-Xresources ;;
*.Xmodmap) style=ftype-Xmodmap ;;
*.xinitrc) style=ftype-xinitrc ;;
*.Xauthority) style=ftype-Xauthority ;;
*.urlview) style=ftype-urlview ;;
*.ttytterrc) style=ftype-ttytterrc ;;
*.profile) style=ftype-profile ;;
*.bash_profile) style=ftype-bash_profile ;;
*.bash_logout) style=ftype-bash_logout ;;
*.zsh) style=ftype-zsh ;;
*.tcsh) style=ftype-tcsh ;;
*.sh*) style=ftype-sh* ;;
*.sh) style=ftype-sh ;;
*.ksh) style=ftype-ksh ;;
*.fish) style=ftype-fish ;;
*.dash) style=ftype-dash ;;
*.csh) style=ftype-csh ;;
*.bash_history) style=ftype-bash_history ;;
*.bash) style=ftype-bash ;;
*.rasi) style=ftype-rasi ;;
*.vimrc) style=ftype-vimrc ;;
*.vimp) style=ftype-vimp ;;
*.viminfo) style=ftype-viminfo ;;
*.vim) style=ftype-vim ;;
*.attheme) style=ftype-attheme ;;
*.tdesktop-pallete) style=ftype-tdesktop-pallete ;;
*.tdesktop-theme) style=ftype-tdesktop-theme ;;
*.theme) style=ftype-theme ;;
*.tfnt) style=ftype-tfnt ;;
*.tfm) style=ftype-tfm ;;
*.tdy) style=ftype-tdy ;;
*.tk) style=ftype-tk ;;
*.tcl) style=ftype-tcl ;;
*.t) style=ftype-t ;;
*.sug) style=ftype-sug ;;
*.sty) style=ftype-sty ;;
*.signature) style=ftype-signature ;;
*.sed) style=ftype-sed ;;
*.ru) style=ftype-ru ;;
*.rb) style=ftype-rb ;;
*.irb) style=ftype-irb ;;
*.erb) style=ftype-erb ;;
*.rc) style=ftype-rc ;;
*.py) style=ftype-py ;;
*.pod) style=ftype-pod ;;
*.pm) style=ftype-pm ;;
*.PL) style=ftype-PL ;;
*.pl) style=ftype-pl ;;
*.pid) style=ftype-pid ;;
*.php) style=ftype-php ;;
*.pfa) style=ftype-pfa ;;
*.pc) style=ftype-pc ;;
*.diff) style=ftype-diff ;;
*.patch) style=ftype-patch ;;
*.pacnew) style=ftype-pacnew ;;
*.offlineimaprc) style=ftype-offlineimaprc ;;
*.nfo) style=ftype-nfo ;;
*.netrc) style=ftype-netrc ;;
*.muttrc) style=ftype-muttrc ;;
*.mtx) style=ftype-mtx ;;
*.msmtprc) style=ftype-msmtprc ;;
*.mi) style=ftype-mi ;;
*.mfasl) style=ftype-mfasl ;;
*.mf) style=ftype-mf ;;
*.map) style=ftype-map ;;
*.lua) style=ftype-lua ;;
*.log) style=ftype-log ;;
*.lesshst) style=ftype-lesshst ;;
*.lam) style=ftype-lam ;;
*.scm) style=ftype-scm ;;
*.lisp) style=ftype-lisp ;;
*.jsp) style=ftype-jsp ;;
*.jsm) style=ftype-jsm ;;
*.js) style=ftype-js ;;
*.e) style=ftype-e ;;
*.java) style=ftype-java ;;
*.info) style=ftype-info ;;
*.htoprc) style=ftype-htoprc ;;
*.agda) style=ftype-agda ;;
*.hs) style=ftype-hs ;;
*.hgignore) style=ftype-hgignore ;;
*.hgrc) style=ftype-hgrc ;;
*.jhtm) style=ftype-jhtm ;;
*.html) style=ftype-html ;;
*.htm) style=ftype-htm ;;
*.gitignore) style=ftype-gitignore ;;
*.git) style=ftype-git ;;
*.fonts) style=ftype-fonts ;;
*.fehbg) style=ftype-fehbg ;;
*.example) style=ftype-example ;;
*.ex) style=ftype-ex ;;
*.etx) style=ftype-etx ;;
*.ps) style=ftype-ps ;;
*.epsi) style=ftype-epsi ;;
*.epsf) style=ftype-epsf ;;
*.eps3) style=ftype-eps3 ;;
*.eps2) style=ftype-eps2 ;;
*.eps) style=ftype-eps ;;
*.enc) style=ftype-enc ;;
*.dir_colors) style=ftype-dir_colors ;;
*.csv) style=ftype-csv ;;
*.less) style=ftype-less ;;
*.scss) style=ftype-scss ;;
*.sass) style=ftype-sass ;;
*.css) style=ftype-css ;;
*.cs) style=ftype-cs ;;
*.coffee) style=ftype-coffee ;;
*.awk) style=ftype-awk ;;
*.mutt) style=ftype-mutt ;;
*.asoundrc) style=ftype-asoundrc ;;
*.asm) style=ftype-asm ;;
*.sqlite) style=ftype-sqlite ;;
*.sql) style=ftype-sql ;;
*.odb) style=ftype-odb ;;
*.mdf) style=ftype-mdf ;;
*.mdb) style=ftype-mdb ;;
*.ldf) style=ftype-ldf ;;
*.db) style=ftype-db ;;
*.ods) style=ftype-ods ;;
*.odp) style=ftype-odp ;;
*.odb) style=ftype-odb ;;
*.pptx) style=ftype-pptx ;;
*.ppt) style=ftype-ppt ;;
*.chrt) style=ftype-chrt ;;
*.xlsx) style=ftype-xlsx ;;
*.xlsm) style=ftype-xlsm ;;
*.xls) style=ftype-xls ;;
*.xla) style=ftype-xla ;;
*.gnumeric) style=ftype-gnumeric ;;
*.rtf) style=ftype-rtf ;;
*.pages) style=ftype-pages ;;
*.odt) style=ftype-odt ;;
*.odm) style=ftype-odm ;;
*.dotm) style=ftype-dotm ;;
*.dot) style=ftype-dot ;;
*.docx) style=ftype-docx ;;
*.docm) style=ftype-docm ;;
*.doc) style=ftype-doc ;;
*.txt) style=ftype-txt ;;
*.mfasl) style=ftype-mfasl ;;
*.mkd) style=ftype-mkd ;;
*.mf) style=ftype-mf ;;
*.org) style=ftype-org ;;
*.md) style=ftype-md ;;
*.markdown) style=ftype-markdown ;;
*.cbz) style=ftype-cbz ;;
*.pdf) style=ftype-pdf ;;
*.mobi) style=ftype-mobi ;;
*.lit) style=ftype-lit ;;
*.fb2) style=ftype-fb2 ;;
*.epub) style=ftype-epub ;;
*.dvi) style=ftype-dvi ;;
*.djvu) style=ftype-djvu ;;
*.djv) style=ftype-djv ;;
*.chm) style=ftype-chm ;;
*.added) style=ftype-added ;;
*.tmp) style=ftype-tmp ;;
*.temp) style=ftype-temp ;;
*.swp) style=ftype-swp ;;
*.pyc) style=ftype-pyc ;;
*.part) style=ftype-part ;;
*.o) style=ftype-o ;;
*.log) style=ftype-log ;;
*.incomplete) style=ftype-incomplete ;;
*.class) style=ftype-class ;;
*.cache) style=ftype-cache ;;
*.blg) style=ftype-blg ;;
*.bbl) style=ftype-bbl ;;
*.bck) style=ftype-bck ;;
*.bak) style=ftype-bak ;;
*.aux) style=ftype-aux ;;
*.ico) style=ftype-ico ;;
*.icns) style=ftype-icns ;;
*.gif) style=ftype-gif ;;
*.yuv) style=ftype-yuv ;;
*.xwd) style=ftype-xwd ;;
*.xcf) style=ftype-xcf ;;
*.svgz) style=ftype-svgz ;;
*.svg) style=ftype-svg ;;
*.bpg) style=ftype-bpg ;;
*.webp) style=ftype-webp ;;
*.png) style=ftype-png ;;
*.pcx) style=ftype-pcx ;;
*.mng) style=ftype-mng ;;
*.eps) style=ftype-eps ;;
*.emf) style=ftype-emf ;;
*.dl) style=ftype-dl ;;
*.CR2) style=ftype-CR2 ;;
*.cgm) style=ftype-cgm ;;
*.tiff) style=ftype-tiff ;;
*.tif) style=ftype-tif ;;
*.xpm) style=ftype-xpm ;;
*.xbm) style=ftype-xbm ;;
*.tga) style=ftype-tga ;;
*.indd) style=ftype-indd ;;
*.psd) style=ftype-psd ;;
*.ppm) style=ftype-ppm ;;
*.pgm) style=ftype-pgm ;;
*.pbm) style=ftype-pbm ;;
*.bmp) style=ftype-bmp ;;
*.JPG) style=ftype-JPG ;;
*.jpg) style=ftype-jpg ;;
*.jpeg) style=ftype-jpeg ;;
*.vdi) style=ftype-vdi ;;
*.vmdk) style=ftype-vmdk ;;
*.qcow2) style=ftype-qcow2 ;;
*.qcow) style=ftype-qcow ;;
*.war) style=ftype-war ;;
*.sar) style=ftype-sar ;;
*.jar) style=ftype-jar ;;
*.ear) style=ftype-ear ;;
*.arj) style=ftype-arj ;;
*.xpi) style=ftype-xpi ;;
*.udeb) style=ftype-udeb ;;
*.rpm) style=ftype-rpm ;;
*.pkg) style=ftype-pkg ;;
*.msi) style=ftype-msi ;;
*.jad) style=ftype-jad ;;
*.gem) style=ftype-gem ;;
*.egg) style=ftype-egg ;;
*.deb) style=ftype-deb ;;
*.cab) style=ftype-cab ;;
*.apk) style=ftype-apk ;;
*.zoo) style=ftype-zoo ;;
*.ZIP) style=ftype-ZIP ;;
*.zip) style=ftype-zip ;;
*.Z) style=ftype-Z ;;
*.Z) style=ftype-Z ;;
*.z) style=ftype-z ;;
*.z) style=ftype-z ;;
*.xz) style=ftype-xz ;;
*.tzo) style=ftype-tzo ;;
*.tz) style=ftype-tz ;;
*.txz) style=ftype-txz ;;
*.tlz) style=ftype-tlz ;;
*.tgz) style=ftype-tgz ;;
*.tbz2) style=ftype-tbz2 ;;
*.tbz) style=ftype-tbz ;;
*.taz) style=ftype-taz ;;
*.tar) style=ftype-tar ;;
*.t7z) style=ftype-t7z ;;
*.rz) style=ftype-rz ;;
*.rar) style=ftype-rar ;;
*.lzma) style=ftype-lzma ;;
*.lzh) style=ftype-lzh ;;
*.lz4) style=ftype-lz4 ;;
*.lz) style=ftype-lz ;;
*.lrz) style=ftype-lrz ;;
*.lha) style=ftype-lha ;;
*.alp) style=ftype-alp ;;
*.gz) style=ftype-gz ;;
*.dz) style=ftype-dz ;;
*.cpio) style=ftype-cpio ;;
*.bz2) style=ftype-bz2 ;;
*.bz) style=ftype-bz ;;
*.arj) style=ftype-arj ;;
*.arc) style=ftype-arc ;;
*.alz) style=ftype-alz ;;
*.ace) style=ftype-ace ;;
*.7z) style=ftype-7z ;;
*.cmd) style=ftype-cmd ;;
*.bat) style=ftype-bat ;;
*.bin) style=ftype-bin ;;
*.btm) style=ftype-btm ;;
*.com) style=ftype-com ;;
*.exe) style=ftype-exe ;;
#--[ End of ftype array ]------@@@@
*) if false; then
elif [[ $arg = $'\x7d' ]] && $right_brace_is_recognised_everywhere; then
# Parsing rule: }
#
# Additionally, `tt(})' is recognized in any position if neither the
# tt(IGNORE_BRACES) option nor the tt(IGNORE_CLOSE_BRACES) option is set.
_zsh_highlight_main__stack_pop 'Y' style=reserved-word
if [[ $style == reserved-word ]]; then
next_word+=':always:'
fi
elif [[ $arg[0,1] = $histchars[0,1] ]] && (( $#arg[0,2] == 2 )); then
style=history-expansion
elif [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR:#"$arg"} ]]; then
if [[ $this_word == *':regular:'* ]]; then
style=commandseparator
else
style=unknown-token
fi
elif (( in_redirection == 2 )); then
style=redirection
else
_zsh_highlight_main_highlighter_highlight_argument
already_added=1
fi
;;
esac
fi
if ! (( already_added )); then
_zsh_highlight_main_add_region_highlight $start_pos $end_pos $style
fi
if [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR:#"$arg"} ]]; then
if [[ $arg == ';' ]] && $in_array_assignment; then
# literal newline inside an array assignment
next_word=':regular:'
else
next_word=':start:'
highlight_glob=true
fi
elif
[[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_CONTROL_FLOW:#"$arg"} && $this_word == *':start:'* ]] ||
[[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS:#"$arg"} && $this_word == *':start:'* ]]; then
next_word=':start:'
elif [[ $arg == "repeat" && $this_word == *':start:'* ]]; then
# skip the repeat-count word
in_redirection=2
# The redirection mechanism assumes $this_word describes the word
# following the redirection. Make it so.
#
# That word can be a command word with shortloops (`repeat 2 ls`)
# or a command separator (`repeat 2; ls` or `repeat 2; do ls; done`).
#
# The repeat-count word will be handled like a redirection target.
this_word=':start::regular:'
fi
start_pos=$end_pos
if (( in_redirection == 0 )); then
# This is the default/common codepath.
this_word=$next_word
else
# Stall $this_word.
fi
done
}
# Check if $arg is variable assignment
_zsh_highlight_main_highlighter_check_assign()
{
setopt localoptions extended_glob
[[ $arg == [[:alpha:]_][[:alnum:]_]#(|\[*\])(|[+])=* ]] ||
[[ $arg == [0-9]##(|[+])=* ]]
}
_zsh_highlight_main_highlighter_highlight_path_separators()
{
local pos style_pathsep
style_pathsep=$1_pathseparator
reply=()
[[ -z "$ZSH_HIGHLIGHT_STYLES[$style_pathsep]" || "$ZSH_HIGHLIGHT_STYLES[$1]" == "$ZSH_HIGHLIGHT_STYLES[$style_pathsep]" ]] && return 0
for (( pos = start_pos; $pos <= end_pos; pos++ )) ; do
if [[ $BUFFER[pos] == / ]]; then
reply+=($((pos - 1)) $pos $style_pathsep)
fi
done
}
# Check if $arg is a path.
# If yes, return 0 and in $REPLY the style to use.
# Else, return non-zero (and the contents of $REPLY is undefined).
_zsh_highlight_main_highlighter_check_path()
{
_zsh_highlight_main_highlighter_expand_path $arg;
local expanded_path="$REPLY" tmp_path
REPLY=path
# [[ -d $expanded_path ]] && return 0
[[ -z $expanded_path ]] && return 1
[[ -L $expanded_path ]] && return 0
[[ -e $expanded_path ]] && return 0
# Check if this is a blacklisted path
if [[ $expanded_path[1] == / ]]; then
tmp_path=$expanded_path
else
tmp_path=$PWD/$expanded_path
fi
tmp_path=$tmp_path:a
while [[ $tmp_path != / ]]; do
[[ -n "${(M)X_ZSH_HIGHLIGHT_DIRS_BLACKLIST:#$tmp_path}" ]] && return 1
tmp_path=$tmp_path:h
done
# Search the path in CDPATH
local cdpath_dir
for cdpath_dir in $cdpath ; do
# [[ -d "$cdpath_dir/$expanded_path" ]] && return 0
[[ -e "$cdpath_dir/$expanded_path" ]] && return 0
done
# If dirname($arg) doesn't exist, neither does $arg.
[[ ! -d ${expanded_path:h} ]] && return 1
# If this word ends the buffer, check if it's the prefix of a valid path.
if [[ ${BUFFER[1]} != "-" && $pure_buf_len == $end_pos ]] &&
[[ $WIDGET != zle-line-finish ]]; then
local -a tmp
tmp=( ${expanded_path}*(N) )
(( $#tmp > 0 )) && REPLY=path_prefix && return 0
fi
# It's not a path.
return 1
}
# Highlight an argument and possibly special chars in quotes
# This command will at least highlight start_pos to end_pos with the default style
_zsh_highlight_main_highlighter_highlight_argument()
{
local base_style=default i path_eligible=1 style
local -a highlights reply
local -a match mbegin mend
local MATCH; integer MBEGIN MEND
if [[ $arg[1] == - ]]; then
if [[ $arg[2] == - ]]; then
base_style=double-hyphen-option
else
base_style=single-hyphen-option
fi
path_eligible=0
fi
for (( i = 1 ; i <= end_pos - start_pos ; i += 1 )); do
case "$arg[$i]" in
"\\") (( i += 1 )); continue;;
"'")
_zsh_highlight_main_highlighter_highlight_single_quote $i
(( i = REPLY ))
highlights+=($reply)
;;
'"')
_zsh_highlight_main_highlighter_highlight_double_quote $i
(( i = REPLY ))
highlights+=($reply)
;;
'`')
_zsh_highlight_main_highlighter_highlight_backtick $i
(( i = REPLY ))
highlights+=($reply)
;;
'$')
path_eligible=0
if [[ $arg[i+1] == "'" ]]; then
path_eligible=1
_zsh_highlight_main_highlighter_highlight_dollar_quote $i
(( i = REPLY ))
highlights+=($reply)
continue
fi
while [[ $arg[i+1] == [\^=~#+] ]]; do
(( i += 1 ))
done
if [[ $arg[i+1] == [*@#?$!-] ]]; then
(( i += 1 ))
fi;;
*)
if $highlight_glob && [[ ${arg[$i]} =~ ^[*?] || ${arg:$i-1} =~ ^\<[0-9]*-[0-9]*\> ]]; then
highlights+=($(( start_pos + i - 1 )) $(( start_pos + i + $#MATCH - 1)) globbing)
(( i += $#MATCH - 1 ))
path_eligible=0
else
continue
fi
;;
esac
done
if (( path_eligible )) && _zsh_highlight_main_highlighter_check_path; then
base_style=$REPLY
_zsh_highlight_main_highlighter_highlight_path_separators $base_style
highlights+=($reply)
fi
highlights=($start_pos $end_pos $base_style $highlights)
_zsh_highlight_main_add_many_region_highlights $highlights
}
# Quote Helper Functions
#
# $arg is expected to be set to the current argument
# $start_pos is expected to be set to the start of $arg in $BUFFER
# $1 is the index in $arg which starts the quote
# $REPLY is returned as the end of quote index in $arg
# $reply is returned as an array of region_highlight additions
# Highlight single-quoted strings
_zsh_highlight_main_highlighter_highlight_single_quote()
{
local arg1=$1 i q=\' style
i=$arg[(ib:arg1+1:)$q]
reply=()
if [[ $zsyh_user_options[rcquotes] == on ]]; then
while [[ $arg[i+1] == "'" ]]; do
reply+=($(( start_pos + i - 1 )) $(( start_pos + i + 1 )) rc-quote)
(( i++ ))
i=$arg[(ib:i+1:)$q]
done
fi
if [[ $arg[i] == "'" ]]; then
style=single-quoted-argument
else
# If unclosed, i points past the end
(( i-- ))
style=single-quoted-argument-unclosed
fi
reply=($(( start_pos + arg1 - 1 )) $(( start_pos + i )) $style $reply)
REPLY=$i
}
# Highlight special chars inside double-quoted strings
_zsh_highlight_main_highlighter_highlight_double_quote()
{
local -a match mbegin mend saved_reply
local MATCH; integer MBEGIN MEND
local i j k style
reply=()
for (( i = $1 + 1 ; i <= end_pos - start_pos ; i += 1 )) ; do
(( j = i + start_pos - 1 ))
(( k = j + 1 ))
case "$arg[$i]" in
'"') break;;
'`') saved_reply=($reply)
_zsh_highlight_main_highlighter_highlight_backtick $i
(( i = REPLY ))
reply=($saved_reply $reply)
continue
;;
'$' ) style=dollar-double-quoted-argument
# Look for an alphanumeric parameter name.
if [[ ${arg:$i} =~ ^([A-Za-z_][A-Za-z0-9_]*|[0-9]+) ]] ; then
(( k += $#MATCH )) # highlight the parameter name
(( i += $#MATCH )) # skip past it
elif [[ ${arg:$i} =~ ^[{]([A-Za-z_][A-Za-z0-9_]*|[0-9]+)[}] ]] ; then
(( k += $#MATCH )) # highlight the parameter name and braces
(( i += $#MATCH )) # skip past it
elif [[ $arg[i+1] == '$' ]]; then
# $$ - pid
(( k += 1 )) # highlight both dollar signs
(( i += 1 )) # don't consider the second one as introducing another parameter expansion
elif [[ $arg[i+1] == [-#*@?] ]]; then
# $#, $*, $@, $?, $- - like $$ above
(( k += 1 )) # highlight both dollar signs
(( i += 1 )) # don't consider the second one as introducing another parameter expansion
elif [[ $arg[i+1] == $'\x28' ]]; then
# Highlight just the '$'.
else
continue
fi
;;
"\\") style=back-double-quoted-argument
if [[ \\\`\"\$${histchars[1]} == *$arg[$i+1]* ]]; then
(( k += 1 )) # Color following char too.
(( i += 1 )) # Skip parsing the escaped char.
else
continue
fi
;;
($histchars[1]) # ! - may be a history expansion
if [[ $arg[i+1] != ('='|$'\x28'|$'\x7b'|[[:blank:]]) ]]; then
style=history-expansion
else
continue
fi
;;
*) continue ;;
esac
reply+=($j $k $style)
done
if [[ $arg[i] == '"' ]]; then
style=double-quoted-argument
else
# If unclosed, i points past the end
(( i-- ))
style=double-quoted-argument-unclosed
fi
reply=($(( start_pos + $1 - 1)) $(( start_pos + i )) $style $reply)
REPLY=$i
}
# Highlight special chars inside dollar-quoted strings
_zsh_highlight_main_highlighter_highlight_dollar_quote()
{
local -a match mbegin mend
local MATCH; integer MBEGIN MEND
local i j k style
local AA
integer c
reply=()
for (( i = $1 + 2 ; i <= end_pos - start_pos ; i += 1 )) ; do
(( j = i + start_pos - 1 ))
(( k = j + 1 ))
case "$arg[$i]" in
"'") break;;
"\\") style=back-dollar-quoted-argument
for (( c = i + 1 ; c <= end_pos - start_pos ; c += 1 )); do
[[ "$arg[$c]" != ([0-9xXuUa-fA-F]) ]] && break
done
AA=$arg[$i+1,$c-1]
# Matching for HEX and OCT values like \0xA6, \xA6 or \012
if [[ "$AA" =~ "^(x|X)[0-9a-fA-F]{1,2}"
|| "$AA" =~ "^[0-7]{1,3}"
|| "$AA" =~ "^u[0-9a-fA-F]{1,4}"
|| "$AA" =~ "^U[0-9a-fA-F]{1,8}"
]]; then
(( k += $#MATCH ))
(( i += $#MATCH ))
else
if (( $#arg > $i+1 )) && [[ $arg[$i+1] == [xXuU] ]]; then
# \x not followed by hex digits is probably an error
style=unknown-token
fi
(( k += 1 )) # Color following char too.
(( i += 1 )) # Skip parsing the escaped char.
fi
;;
*) continue ;;
esac
reply+=($j $k $style)
done
if [[ $arg[i] == "'" ]]; then
style=dollar-quoted-argument
else
# If unclosed, i points past the end
(( i-- ))
style=dollar-quoted-argument-unclosed
fi
reply=($(( start_pos + $1 - 1 )) $(( start_pos + i )) $style $reply)
REPLY=$i
}
# Highlight backtick subshells
_zsh_highlight_main_highlighter_highlight_backtick()
{
local arg1=$1 i=$1 q=\` style
reply=()
while i=$arg[(ib:i+1:)$q]; [[ $arg[i-1] == '\' && $i -lt $(( end_pos - start_pos )) ]]; do done
if [[ $arg[i] == '`' ]]; then
style=back-quoted-argument
else
# If unclosed, i points past the end
(( i-- ))
style=back-quoted-argument-unclosed
fi
reply=($(( start_pos + arg1 - 1 )) $(( start_pos + i )) $style)
REPLY=$i
}
# Called with a single positional argument.
# Perform filename expansion (tilde expansion) on the argument and set $REPLY to the expanded value.
#
# Does not perform filename generation (globbing).
_zsh_highlight_main_highlighter_expand_path()
{
(( $# == 1 )) || print -r -- >&2 "zsh-syntax-highlighting: BUG: _zsh_highlight_main_highlighter_expand_path: called without argument"
# The $~1 syntax normally performs filename generation, but not when it's on the right-hand side of ${x:=y}.
setopt localoptions nonomatch
unset REPLY
: ${REPLY:=${(Q)${~1}}}
}
# -------------------------------------------------------------------------------------------------
# Main highlighter initialization
# -------------------------------------------------------------------------------------------------
_zsh_highlight_main__precmd_hook() {
_zsh_highlight_main__command_type_cache=()
}
autoload -U add-zsh-hook
if add-zsh-hook precmd _zsh_highlight_main__precmd_hook 2>/dev/null; then
# Initialize command type cache
typeset -gA _zsh_highlight_main__command_type_cache
else
print -r -- >&2 'zsh-syntax-highlighting: Failed to load add-zsh-hook. Some speed optimizations will not be used.'
# Make sure the cache is unset
unset _zsh_highlight_main__command_type_cache
fi
typeset -ga X_ZSH_HIGHLIGHT_DIRS_BLACKLIST
|
x
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | # -------------------------------------------------------------------------------------------------
# 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_highlighter_pattern_predicate()
{
_zsh_highlight_buffer_modified
}
# Pattern syntax highlighting function.
_zsh_highlight_highlighter_pattern_paint()
{
setopt localoptions extendedglob
local pattern
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
local MATCH; integer MBEGIN MEND
if [[ "$buf" == (#b)(*)(${~pat})* ]]; then
region_highlight+=("$((mbegin[2] - 1)) $mend[2] $ZSH_HIGHLIGHT_PATTERNS[$pat]")
"$0" "$match[1]" "$pat"; return $?
fi
}
|
x
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | # -------------------------------------------------------------------------------------------------
# Copyright (c) 2010-2016 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_REGEXP
# Whether the pattern highlighter should be called or not.
_zsh_highlight_highlighter_regexp_predicate()
{
_zsh_highlight_buffer_modified
}
# Pattern syntax highlighting function.
_zsh_highlight_highlighter_regexp_paint()
{
setopt localoptions extendedglob
local pattern
for pattern in ${(k)ZSH_HIGHLIGHT_REGEXP}; do
_zsh_highlight_regexp_highlighter_loop "$BUFFER" "$pattern"
done
}
_zsh_highlight_regexp_highlighter_loop()
{
local buf="$1" pat="$2"
integer OFFSET=0
local MATCH; integer MBEGIN MEND
local -a match mbegin mend
while true; do
[[ "$buf" =~ "$pat" ]] || return;
region_highlight+=("$((MBEGIN - 1 + OFFSET)) $((MEND + OFFSET)) $ZSH_HIGHLIGHT_REGEXP[$pat]")
buf="$buf[$(($MEND+1)),-1]"
OFFSET=$((MEND+OFFSET));
done
}
|
x
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | # -------------------------------------------------------------------------------------------------
# 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_highlighter_root_predicate()
{
_zsh_highlight_buffer_modified
}
# root highlighting function.
_zsh_highlight_highlighter_root_paint()
{
if (( EUID == 0 )) { _zsh_highlight_add_highlight 0 $#BUFFER root }
}
|
x
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | #!/usr/bin/env zsh
# Whether the pattern highlighter should be called or not.
_zsh_highlight_url_highlighter_predicate()
{
_zsh_highlight_buffer_modified
}
# Pattern syntax highlighting function.
_zsh_highlight_url_highlighter()
{
setopt localoptions extendedglob
_zsh_highlight_url_highlighter_loop "$BUFFER" "(^https?://[^\n'\"]*) "
}
_zsh_highlight_url_highlighter_loop()
{
# This does *not* do its job syntactically, sorry.
local buf="$1" pat="$2"
local -a match mbegin mend
if [[ "$buf" =~ "${pat}" ]]; then
curl -sIL -m 4 -w '' "${match}" -o /dev/null
local exitCode=$?
if [[ "$exitCode" -eq "0" ]]; then
region_highlight+=("$((mbegin[1] - 1)) $mend[1] fg=green")
"$0" "$match" "$pat"; return $?
else
region_highlight+=("$((mbegin[1] - 1)) $mend[1] fg=red")
"$0" "$match" "$pat"; return $?
fi
fi
}
|
x
Notes
My zsh config putted in ~/.config/zsh
It use zsh-defer for faster startup, zsh highlight with filetype colors generated from dircolors with cusrom script.
Dotfiles:
https://github.com/neg-serg/dotfiles
Dir struct:
01-init.zsh
05-cmds.zsh
03-exports.zsh
03-helpers.zsh
03-xdg_vars.zsh
04-prompt.zsh
12-completion.zsh
13-bindkeys.zsh
70-forgit.zsh
81-completion_gen.zsh
96-fzf.zsh
98-syntax.zsh
highlighters/cursor-highlighter.zsh
highlighters/root-highlighter.zsh
highlighters/brackets-highlighter.zsh
highlighters/pattern-highlighter.zsh
highlighters/regexp-highlighter.zsh
highlighters/line-highlighter.zsh
highlighters/url-highlighter.zsh
highlighters/ft_list.zsh
highlighters/main-highlighter.zsh
zsh-defer/zsh-defer.plugin.zsh