#-------------------#--------------------# # # #=- a dance amongst unicorns, by satan -=# # # #-------------------#--------------------# 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 ) # }}} # parameters {{{ export \ PATH FPATH CDPATH GREP_COLORS \ HOSTNAME=${HOSTNAME:-localhost} \ EDITOR=/usr/bin/vim \ VISUAL=/usr/bin/vim \ PAGER=/usr/bin/most \ MANPAGER=/usr/bin/vimpager \ BROWSER=/usr/bin/elinks \ GIT_COMMITTER_NAME=$USER \ GIT_AUTHOR_NAME=$USER \ EMAIL='like100ninjas.mail@gmail.com' \ ELINKS_XTERM='st -e' \ XAUTHORITY=$HOME/var/cache/.Xauthority \ XDG_CONFIG_HOME=$HOME/etc \ XDG_DATA_HOME=$HOME/var \ XDG_CACHE_HOME=$HOME/var/cache \ XDG_DOWNLOAD_DIR=$HOME/downloads \ TRASH_DIR=$HOME/var/tmp \ ELINKS_CONFDIR=$HOME/etc/elinks \ WWW_HOME='https://www.archlinux.org' \ GNUPG_HOME=$HOME/etc/gpg # saved_config_dirs: # userdirs=/ / / / / /srv/ftp / / /srv/http /root / / /var/spool/mail / / /bin /home/tyrannopath / / / / / /var/lib/colord # end_1 ZDOTDIR=${ZDOTDIR:-$HOME} HISTFILE=$XDG_CACHE_HOME/.zsh_history HISTSIZE=1000 SAVEHIST=$HISTSIZE LOGCHECK=30 watch=(notme) # }}} # directories {{{ local \ name val \ exclude=( $WWW_HOME $XDG_RUNTIME_DIR ) \ bin_home=$HOME/bin \ dev_home=$HOME/src \ fun_home=$HOME/etc/zsh/functions 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=( $bin_home $( (print - $bin_home/**/*(/)) 2>/dev/null) {/usr{/local,},}{/bin,/sbin} $( (print - /usr/bin/*_perl(/)) 2>/dev/null) ) _path_add path tmp_path=( $fun_home $( (print - $fun_home/**/*(/)) 2>/dev/null) $( (print - /usr/share/zsh/*functions(/)) 2>/dev/null) $( (print - /usr/share/zsh/*functions/**/*(/)) 2>/dev/null) ) _path_add fpath tmp_path=( $HOME $XDG_CONFIG_DIR $XDG_DATA_DIR ) _path_add cdpath unfunction _path_add # }}} # keybindings {{{ if [[ $TERM =~ .*color ]] 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 #}}} # functions {{{ local func fun_spot=( $( (print - $fun_home/**/*~*.swp~*.zwc(.)) 2>/dev/null) ) for func in $fun_spot; do autoload -U $func done precmd() { PS1='%K{0} %F{1}error%F{7}: %F{3}prompt borken %k %F{2}» %f' _set_prompt 2>/dev/null if [[ $TERM =~ .*color ]] then print -Pn "\e]0;%n@%m:%~\a" fi print - '' } preexec() { if [[ $TERM =~ .*color ]] then print -Pn "\e]0;$1\a" fi print - '' } chpwd() { ls -AFX --group-directories-first --color='auto' } autoload -U \ run-help \ tetris \ zcalc \ compinit && compinit -d $XDG_CACHE_DIR/zsh_comp_dump # }}} # _set_prompt() {{{ _set_prompt() { local \ dir=$PWD:t \ branch=$( (git symbolic-ref --short HEAD) 2>/dev/null) \ dir=${dir//$USER/\\\$HOME} PS1="%K{0} %F{4}$dir %k %F{2}» %f" PS2="%K{0} %F{4}$_ %k %F{2}» %f" RPS1='' 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{0} %F{3}$branch" if (( $behind )) then RPS1+="%F{1} -$behind" fi if (( $ahead )) then RPS1+="%F{2} +$ahead" fi RPS1+=" %f%k" fi } # }}} # _save_config_dirs() {{{ _save_config_dirs() { local name val string where=$ZDOTDIR/.zshrc lol=saved_ for name in ${(k)parameters}; do val=${(P)name} if [[ ${(L)name} =~ .*(dir|home) && -n $val ]] then if [[ -z $( (grep "$name=$val" $where) 2>/dev/null) ]] then string="export $name=$val" sed -i '/'$lol'config_dirs:/a '$string $where fi fi done } # }}} # _save_aliases() {{{ _save_aliases() { local name num string val where=$ZDOTDIR/.zshrc while (( $# )); do if [[ ! $1 =~ (aliases|galiases|saliases) ]] then shift continue fi for name in $(eval 'print - ${(k)'$1'}'); do eval 'val=${'$1'['$name']}' if [[ -z $( (agrep -e $name'.*'$val $where) 2>/dev/null) && -n $val ]] then string=$name num=$(( 10 - ${#name} )) if (( num > 0 )) then while (( num )); do string+=' ' num=$(( num - 1 )) done else string+=' ' fi string+=\"$val\" sed -i '/saved_'$1':/a '$string $where fi done shift done } # }}} # obliterate() {{{ obliterate() { local \ where=$ZDOTDIR/.zshrc lol=saved_ \ valid=( configdirs aliases galiases saliases ) \ usage='obliterate: usage `obliterate (configdirs|aliases|galiases|saliases)' if (( $# == 0 )) then print - $usage return 1 elif [[ -z ${@:*valid} ]] then print - $usage return 1 elif [[ -n ${@:|valid} ]] then print - "obliterate: bad argument(s): ${@:|valid}" return 1 fi while (( $# )); do case $1 in configdirs) sed -i '/'$lol'config_dirs:/,/end_1/c # '$lol'config_dirs\n# end_1' $where ;; aliases) sed -i '/'$lol'aliases:/,/end_2/c # '$lol'aliases\n# end_2' $where ;; galiases) sed -i '/'$lol'galiases:/,/end_3/c # '$lol'galiases\n# end_3' $where ;; saliases) sed -i '/'$lol'saliases:/,/end_4/c # '$lol'saliases\n# end_4' $where ;; esac shift done } # }}} # trash() {{{ trash() { local piece if (( $# == 1 )) && [[ $1 == 'dump' ]] then rm -rf $TRASH_DIR/* return 0 elif (( $# == 0 )) then print - 'trash: usage: `trash file [ ...file ]'\' print - ' OR `trash dump'\' return 0 elif [[ ! -d $TRASH_DIR || ! -O $TRASH_DIR ]] then print - 'trash: go define $TRASH_DIR' &>2 return 1 fi for piece in $@; do if [[ ! -O $piece ]] then print - "trash: invalid piece of trash: $piece" &>2 return 1 fi done while (( $# )); do mv -f $1 $TRASH_DIR shift done } # }}} # aliases {{{ unalias run-help aliases=( ahack 'telnet nethack.alt.org' grep 'grep --color=auto' egrep 'egrep --color=auto' fgrep 'fgrep --color=auto' help 'run-help' la 'ls -AFX --group-directories-first --color=auto' ll 'ls -fgGhX --group-directories-first --color=auto --time-style=+' lla 'ls -AfgGhX --group-directories-first --color=auto --time-style=+' ls 'ls -FX --group-directories-first --color=auto' pg "!! | $PAGER" rm 'rm -r' save '_save_config_dirs; _save_aliases aliases galiases saliases' su 'su -' # saved_aliases: # end_2 ) galiases=( ... '../..' .... '../../..' xG '| grep' xH '| head' xL '| less' xM '| more' xP "| $PAGER" xT '| tail' # saved_galiases: # end_3 ) saliases=( # saved_saliases: # end_4 ) # }}} # colors {{{ typeset -TUx LS_COLORS dircolors=( {fi,no}'=0;90' di'=00;34' ex'=00;32' ln'=00;33' or'=00;31' mi'=05;31' {pi,so}'=00;35' {bd,cd}'=00;36' lc'=\e[' ) GREP_COLORS='mt=00;34:fn=00;36: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{1}%d%f' zstyle ':completion:*:messages' format '%F{2}%d%f' zstyle ':completion:*:corrections' format '%F{3}%d%f' zstyle ':completion:*:descriptions' format '%F{4}%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' 'systemd*' 'uuidd' zstyle ':completion:*' list-colors $dircolors 'ma=00;40' zstyle ':completion:*:*:kill:*' list-colors "=(#b) #([0-9]#)*=36=31" zstyle ':completion:*:*:kill:*:jobs' list-colors "=(#b) #([0-9]#)*=35=31" zstyle ':completion:*' use-cache on zstyle ':completion:*' cache-path \ "$XDG_CACHE_DIR/zsh_comp_cache" # }}} trap '_save_config_dirs; _save_aliases aliases galiases saliases' EXIT QUIT # vim: set fdm=marker ts=8 sts=2 ft=zsh: