#!/bin/zsh if [[ ! -o interactive ]] then return; fi zmodload zsh/complist zsh/parameter zsh/regex zsh/zutil 2>/dev/null # options options=( autoresume on beep off completealiases on completeinword on extendedglob on menucomplete on multios on notify on promptsubst on histignorealldups on histignorespace on histnofunctions on histnostore on histreduceblanks on sharehistory on vi on ) # variables export \ FPATH GREP_COLORS PATH \ BROWSER=/usr/bin/lynx \ EDITOR=/usr/bin/vim \ MANPAGER=/usr/bin/less\ PAGER=/usr/bin/less \ XAUTHORITY=$HOME/.cache/.Xauthority \ XDG_CONFIG_HOME=$HOME/.config \ XDG_DATA_HOME=$HOME/.local/share \ XDG_CACHE_HOME=$HOME/.cache \ XDG_DOCUMENTS_DIR=$HOME/files/documents \ XDG_DOWNLOAD_DIR=$HOME/downloads \ XDG_MUSIC_DIR=$HOME/files/music \ XDG_PICTURES_DIR=$HOME/files/pictures \ XDG_VIDEOS_DIR=$HOME/files/videos HISTFILE=$XDG_CACHE_HOME/.zsh_history HISTSIZE=20 LOGCHECK=30 SAVEHIST=0 watch=( notme ) # directories local \ name val \ exclude=( $XDG_RUNTIME_DIR ) \ script_home=$HOME/scripts/zsh umask 077 for name in ${(k)parameters}; do val=${(P)name:|exclude} if [[ ${(L)name} =~ .*(dir|home)$ && -n $val ]] then mkdir -p $val fi done # paths local -U tmp_path _path_add() { local dir; eval unset $1 for dir in $tmp_path; do if [[ -d $dir ]] then eval $1+=$dir fi done } tmp_path=( {,/usr{,/local}}{/bin,/sbin} $((print - /usr/bin/*_perl(/)) 2>/dev/null) ) _path_add path tmp_path=( $script_home $((print - $script_home/**/*(/)) 2>/dev/null) $((print - /usr/share/zsh/**/*(/)) 2>/dev/null) ) _path_add fpath tmp_path=( $HOME $XDG_CONFIG_HOME $XDG_DATA_HOME ) _path_add cdpath unfunction _path_add # keybindings if [[ $TERM =~ .*(color|xterm).* ]] then bindkey \ '^[[H' beginning-of-line \ '^[[4h' overwrite-mode \ '^[[P' delete-char fi bindkey \ '^[[1~' beginning-of-line \ '^[[2~' overwrite-mode \ '^[[3~' delete-char \ '^[[4~' end-of-line \ '^[[5~' beginning-of-buffer-or-history \ '^[[6~' end-of-buffer-or-history \ '^[[A' up-line-or-history \ '^[[B' down-line-or-history \ '^[[C' forward-char \ '^[[D' backward-char \ '^?' backward-delete-char \ ' ' magic-space \ '\t' complete-word bindkey -M menuselect \ '^[[2~' vi-insert \ '^[[5~' backward-word \ '^[[6~' forward-word \ '^?' undo \ ' ' accept-and-menu-complete \ '\t' accept-and-infer-next-history # scripts local scripts=( $((print - $script_home/**/*~*.swp~*.zwc(.)) 2>/dev/null) ) for func in $scripts; do autoload -U $func done _git_prompt() { local branch=$((git symbolic-ref --short HEAD) 2>/dev/null) if [[ -n $branch ]] then local \ gdir=$((git --rev-parse --git-dir) 2>/dev/null) \ behind=$((git log --oneline ..@{u} | wc -l | tr -d ' ') 2>/dev/null) \ ahead=$((git log --oneline @{u}.. | wc -l | tr -d ' ') 2>/dev/null) if [[ -r $gdir/MERGE_HEAD ]] then RPS1+='%F{5}⚡ ' fi if [[ -n $((git ls-files --other --exclude-standard) 2>/dev/null) ]] then RPS1+='%F{1}•' fi if [[ -n $((git diff | cat) 2>/dev/null) ]] then RPS1+='%F{3}•' fi if [[ -n $((git diff --cached | cat) 2>/dev/null) ]] then RPS1+='%F{2}•' fi RPS1+=" %K{7} %F{3}$branch" if (( $behind )) then RPS1+="%F{1} -$behind" fi if (( $ahead )) then RPS1+="%F{2} +$ahead" fi RPS1+=' %f%k' fi } precmd() { local dir=$PWD:t dir=${dir//$USER/\\\$HOME} PS1="%F{10}» %f" PS2="%F{10}» %f" RPS1='' if [[ -x /usr/bin/git ]] then _git_prompt fi if [[ $TERM =~ .*(color|xterm).* ]] then print -Pn "\e]0;%n@%m:%~\a" fi print - '' } preexec() { if [[ $TERM =~ .*(color|xterm).* ]] then print -Pn "\e]0;$1\a" fi if [[ -n @a ]] then print - '' fi } autoload -U \ run-help \ compinit && compinit -d $XDG_CACHE_DIR/zsh_comp_dump # aliases unalias run-help aliases=( egrep 'egrep --color=auto' fgrep 'fgrep --color=auto' grep 'grep --color=auto' help 'run-help' ll 'ls -AFgGhX --group-directories-first --color=auto --time-style=+' ls 'ls -AFX --group-directories-first --color=auto' pg "!! | $PAGER" ) galiases=( ... '../..' .... '../../..' xG '| grep' xH '| head' xL '| less' xM '| more' xP "| $PAGER" xT '| tail' ) # colors typeset -TUx LS_COLORS dircolors=( {no,fi}'=00;37' di'=00;94' ex'=00;92' ln'=00;97' or'=00;91' mi'=00;91' {pi,so}'=00;93' {bd,cd}'=00;95' lc'=\e[' ) GREP_COLORS='mt=00;94:fn=00;96:ln=00;33:se=00;90' # completion zstyle ':completion:*' squeeze-slashes true zstyle ':completion:*' matcher-list \ '' 'm:{a-z-}={A-Z_}' 'r:|[._-/]=* r:|=*' zstyle ':completion:*' completer \ _complete _match _ignored zstyle ':completion:*:*:(cd|kill|ls|mv|rename|rm|vim):*' menu \ yes select zstyle ':completion:*:*:(cd|kill|ls|mv|rename|rm|vim):*' force-list \ always zstyle ':completion:*:*:(cd|kill|ls|mv|rename|rm|vim):*' ignore-parents \ parent pwd zstyle ':completion:*:*:(cd|kill|ls|mv|rename|rm|vim):*' list-dirs-first zstyle ':completion:*:warnings' format '%F{9}%d%f' zstyle ':completion:*:messages' format '%F{10}%d%f' zstyle ':completion:*:corrections' format '%F{11}%d%f' zstyle ':completion:*:descriptions' format '%F{12}%d%f' zstyle ':completion:*:functions' ignored-patterns '_*' zstyle ':completion:*:*:*:users' ignored-patterns \ 'avahi' 'bin' 'colord' 'daemon' 'dbus' 'ftp' 'git' 'http' 'mail' \ 'mpd' 'nobody' 'nvidia*' 'polkitd' '*' 'uuidd' zstyle ':completion:*' list-colors $dircolors 'ma=00;100' zstyle ':completion:*:*:kill:*' list-colors "=(#b) #([0-9]#)*=96=91" zstyle ':completion:*:*:kill:*:jobs' list-colors "=(#b) #([0-9]#)*=95=91" zstyle ':completion:*' use-cache on zstyle ':completion:*' cache-path \ "$XDG_CACHE_DIR/zsh_comp_cache"