## vim:ft=zsh:foldmethod=marker ## Copyright (c) 2008, 2009 by Daniel Friesel ## Licence: ## 0. You just DO WHAT THE FUCK YOU WANT TO. ## ## https://derf.homelinux.org/~derf/dotfiles/zsh/rc ## see also: https://derf.homelinux.org/~derf/dotfiles/zsh/ # {{{ OS Detection system=${$(uname):l} alias 'linux:'='[[ $system == linux ]] &&' if [[ $system == linux ]] { [[ -f /etc/debian_version ]] && distro=debian } # }}} # {{{ Startup infos function zrc_info { print -P "%F{red}>>%F{default} $*" } # }}} # {{{ Options setopt auto_pushd pushd_ignore_dups pushd_minus pushd_silent setopt auto_cd setopt transient_rprompt setopt list_packed setopt extended_glob unsetopt bang_hist setopt correct # greedy is more like dvorak than qwerty... setopt dvorak unsetopt flow_control setopt rc_quotes unsetopt beep # }}} # {{{ Shell parameters ## parameters which are only important for interactive shells. ## For application-related parameters, see .zshenv if [[ -d ~/var/cache/zsh ]] { ZCACHEDIR=~/var/cache/zsh } else { mkdir -p ~/.zsh-cache ZCACHEDIR=~/.zsh-cache } HISTFILE=$ZCACHEDIR/history HISTSIZE=50000 SAVEHIST=$HISTSIZE DIRSTACKSIZE=20 # Use the full terminal size for listings LISTMAX=0 TIMEFMT='%J (%P) - %*E real, %*U user, %*S system' if (( EUID != 0)) { path+=(/sbin /usr/sbin /usr/local/sbin) } export MAKEFLAGS=j$(grep -c '^processor' /proc/cpuinfo) typeset -U path path=(~/bin $path) # Add manuals from caretaker to manpath if [[ $distro == debian ]] { if [[ -e ~/packages/catman ]] { export MANPATH=/var/cache/man } else { export MANPATH=/usr/share/man if (( COLUMNS > 100 )) { export MANWIDTH=100 } } MANPATH+=":/usr/local/share/man:$HOME/packages/.collected/man" } # }}} # {{{ MIME parameters mime_archive=( 7z ace arj bz bz2 cpio deb dz gz jar lzh lzma rar rpm rz svgz tar taz tbz2 tgz tz z Z zip zoo ) mime_audio=( aif aifc aiff amr amr au awb awb axa flac gsm kar m3u m3u m4a mid midi mp2 mp3 mpega mpga oga ogg pls ra ra ram rm sd2 sid snd spx wav wax wma ) mime_document=(pdf ps) mime_image=( art bmp cdr cdt cpt cr2 crw djv djvu erf gif ico ief jng jpe jpeg jpg nef orf pat pbm pcx pgm png pnm ppm psd ras rgb svg svgz tif tiff wbmp xbm xpm xwd ) mime_video=( 3gp asf asx avi axv dif divx dl dv fli flv gl lsf lsx m2t mkv mng mov movie mp4 mpe mpeg mpg mpv mxu ogm ogv qt rmvb wm wmv wmx wvx ) # }}} # {{{ ls-colors (partially based on MIME) # default:file :dirctory: link : pipe : socket LS_COLORS="no=00:fi=00:di=01;37:ln=01;36:pi=40;33:so=01;35" # door : block dev : char dev :broken link: setuid LS_COLORS+=":do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:su=37;41" # setgid : +t,o+w : o+w : sticky : executable LS_COLORS+=":sg=30;43:tw=30;42:ow=34;42:st=37;44:ex=01;32" LS_COLORS+=:${(j/:/):-"*."${^mime_archive}"=04;31"} LS_COLORS+=:${(j/:/):-"*."${^mime_audio}"=04;36"} LS_COLORS+=:${(j/:/):-"*."${^mime_document}"=04"} LS_COLORS+=:${(j/:/):-"*."${^mime_image}"=04;33"} LS_COLORS+=:${(j/:/):-"*."${^mime_video}"=04;32"} export LS_COLORS # }}} # {{{ Functions autoload -U compinit autoload zargs zmv if [[ -e $ZDIR/functions ]] { autoload $ZDIR/functions/*(:t) } else { # No cool extra stuff zrc_info "Running in standalone mode" # rtab is tracked in functions/, so it may not be present everywhere. # However, the prompt assumes the presence of a 'rtab' function. function rtab { print -P %~ } } # This all belongs into the prompt, but since it only changes # when changing directories, it's more efficient to do it here function chpwd { psvar[1]=$(dirinfo) psvar[2]=$(rtab) } function dirinfo { typeset string [[ -r .todo ]] && string+='todo ' [[ -f .fehindex.jpg ]] && string+='feh ' [[ -d .hg ]] && string+='hg ' [[ -d .git ]] && string+='git ' [[ -d .svn ]] && string+='svn ' [[ -f Makefile || -f makefile ]] && string+='make ' # if we're running in screen, we're the only one writing into the prompt # -> no trailing whitespace if [[ $TERM == screen* ]] { echo ${string% } } else { echo $string } } # Inspired by salias from the grml zshrc function salias { typeset key=${1%%\=*} val=${1#*\=} if (( EUID == 0 )) { alias -- $key=$val } else { alias -- $key="sudo $val" } } function xhashd { typeset directory=${~1#*\=} name=${1%%\=*} if [[ -d $directory ]] { hash -d $name=$directory } } # Note: local assignments (typeset foo=bar) are lost. export foo=bar works. function xsource { if [[ -r $1 ]] { source $1 } } function Status Start Stop Restart Reload { typeset script sudo if ((EUID)) { sudo=sudo } for script in $*; { $sudo /etc/init.d/$script ${0:l} } } # }}} # {{{ ZLE autoload -U url-quote-magic zle -N self-insert url-quote-magic # }}} # {{{ Prompt # RPS1 is on the right side of the terminal # The \ek\e\\ is for screen's 'shelltitle' # psvar[1] = directory info # psvar[2] = rtab (current directory) typeset -A ps rps ps=( host "%F{yellow}%m" dir "%F{default}%30<…<%2v%>>" sign "%(!.%F{red}.%F{green})%(?.%(!.#.>).%?)%F{default}" screen $'%{\ek\e\\%}' ) rps=( start_always "%F{yellow}[" start_screen "%(1V.%F{yellow}[" dirinfo "%F{default}%1v" time '%T' end_always "%F{yellow}]%F{default}" end_screen "%(1V.%F{yellow}]%F{default}.)" ) PS1="${ps[host]} ${ps[dir]} ${ps[sign]} ${ps[screen]}" if [[ $TERM == screen* ]] { RPS1="${rps[start_screen]}${rps[dirinfo]}${rps[end_screen]}" } else { RPS1="${rps[start_always]}${rps[dirinfo]}${rps[time]}${rps[end_always]}" } unset ps rps zstyle ':prompt:rtab' fish yes zstyle ':prompt:rtab' nameddirs yes # }}} # {{{ Named directories hash -d vcs=~/var/svn xhashd lyrics=~vcs/lyrics xhashd www=/var/www xhashd web=~/public_html # }}} # {{{ Keys bindkey -e [[ -z $terminfo[kdch1] ]] || bindkey -M emacs $terminfo[kdch1] delete-char [[ -z $terminfo[khome] ]] || bindkey -M emacs $terminfo[khome] beginning-of-line [[ -z $terminfo[kend] ]] || bindkey -M emacs $terminfo[kend] end-of-line # }}} # {{{ Aliases # {{{ Suffix typeset -A alias_apps alias_apps=( archive extract audio mplayer document kpdf image feh video mplayer ) for meta in ${parameters[(I)mime_*]#mime_}; { for format in $(eval echo "$"mime_$meta); { alias -s $format=$alias_apps[$meta] } } unset filetypes meta format alias_apps # }}} # {{{ Defaults # To evade these defaults, use '=command' instead of 'command' linux: { alias egrep='grep -E --color=auto' alias fgrep='grep -F --color=auto' alias grep='grep --color=auto' alias bzgrep='bzgrep --color=auto' alias zgrep='zgrep --color=auto' } linux: alias df='df -hl --exclude-type=fuse.encfs' || alias df='df -hl' linux: alias du='du -shD' || alias du='du -shH' linux: alias ls='ls -h --color=auto' || alias ls='ls -h' ## enable alias expansion alias exec='exec ' alias sudo='sudo ' linux: salias netstat='netstat --program --all --tcp --extend' || salias netstat='netstat -atp tcp' alias bc='bc -l' alias fbi='fbi -readahead' alias cp='cp -i' alias mv='mv -i' alias pmount='pmount -A' alias find='noglob find' alias man='man -a' # ps -C foo is better than ps aux | fgrep foo ;-) alias ps='ps -F' alias todo='noglob todo -f +children' # }}} # {{{ Global # global aliases are slightly evil, but (usually) not messy alias -g EG='|egrep' alias -g FG='|fgrep' alias -g G='|grep' alias -g H='|head' alias -g L='|less' alias -g T='|tail' # }}} # {{{ Loop me alias allf='for i in *(.);' alias alld='for i in *(/);' alias alle='for i in *(*);' alias alll='for i in *(@);' alias all='for i in *;' alias allfr='for i in **/*(.);' alias alldr='for i in **/*(/);' alias aller='for i in **/*(*);' alias alllr='for i in **/*(@);' alias allr='for i in **/*;' # }}} # {{{ Short (similar to default options) alias dua='du --apparent-size' alias lasth='last | head -$((LINES-1))' alias fbif='fbi -a' alias fbij='fbi -a -u' for i in ~/var/gtd/*(.N); { alias gtd-${i:t}='todo --database '$i } alias lsi='feh --list' alias lst='tar tvf' alias lsz='unzip -l' alias nb='newsbeuter' alias nbr='newsbeuter -r' alias rd='rmdir' alias rsync-serve="rsync --daemon --port=10873 --no-detach --config=/dev/stdin --log-file=/dev/stdout -v <<< $'[.]\n\tpath = .\n\tuse chroot = no'" # Mateguthaben in CCC-Erfas u.ä. alias mate='decrement ~/stuff/$(cat ~/var/tmp/.actual-location)/mateguthaben' alias x='unsetopt bg_nice; startx &! exit' # }}} if [[ $distro == debian ]] { #{{{ alias acse='apt-cache search' alias afse='apt-file search' alias apse='aptitude search' alias acp='apt-cache policy' alias acsh='apt-cache show' alias afsh='apt-file show' alias apsh='aptitude show' alias dps='dpkg --status' salias agu='apt-get update' salias apu='aptitude update' salias ags='apt-get upgrade' salias agf='apt-get dist-upgrade' salias aps='aptitude safe-upgrade' salias apf='aptitude full-upgrade' salias agi='apt-get install' salias api='aptitude install' salias dpi='dpkg --install' salias agc='apt-get clean' salias apc='aptitude clean' salias agar='apt-get autoremove' salias agp='apt-get purge' salias agr='apt-get remove' salias dpp='dpkg --purge' salias dpr='dpkg --remove' alias agsrc='apt-get source' salias dprc='dpkg-reconfigure' } #}}} if [[ -e /tmp/.x-started ]] { #{{{ alias feh='feh --quiet --verbose --action8 "mkdir -p .rm; mv '\'%f\'' .rm"' # Alias structure: # feh[theme][recursive?][slide-delay?] # theme = [f]ullscreen | [i]ndex | [j]ust | [t]humbnail # recursive: r for recursive, nothing otherwise # slide-delay: # none - no slideshow # number - slideshow, $number seconds per image # x - slideshow, seconds will be specified on commandline # (like "fehfrx 7 .") # The themes are defined in ~/.fehrc alias fehf='feh -Tfull' alias fehfr='feh -Tfull --recursive' alias fehi='feh .fehindex.jpg' alias fehj='feh -Tjust' alias fehjr='feh -Tjust --recursive' for i in {5,10,15,20}; { alias fehj$i="feh -Tjust --slideshow-delay $i" alias fehf$i="feh -Tfull --slideshow-delay $i" alias fehjr$i="feh -Tjust --slideshow-delay $i --recursive" alias fehfr$i="feh -Tfull --slideshow-delay $i --recursive" } alias fehjx='feh -Tjust --slideshow-delay' alias fehfx='feh -Tfull --slideshow-delay' alias fehjrx='feh -Tjust --recursive --slideshow-delay' alias fehfrx='feh -Tfull --recursive --slideshow-delay' alias feht='feh -Tthumbnail' alias fehtr='feh -Tthumbnail --recursive' alias putscreen='put $(screenshot)' alias weather='feh http://www.bredeney-wetter.de/aktuell.gif' } #}}} # }}} # {{{ Misc mesg n if ((UID)) { umask 077 } else { umask 002 } chpwd # }}} # {{{ Includes # no xsource here - typeset may be used if [[ -e $ZDIR/../provided/includes ]] { source $ZDIR/../provided/includes } # local configuration, not in git xsource $ZDIR/local [[ -n $commands[envstore] ]] && eval $(envstore eval) # local configuration, in git xsource $ZDIR/hosts/$HOST # }}} # {{{ Completion zstyle ':completion:*' cache-path $ZCACHEDIR zstyle ':completion:*' use-cache true zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS} zstyle ':completion:*' menu select=1 # Complete uppercase chars with lowercase ones, spaces with _, # start completion somewhere else than the beginning of the word if neccessary zstyle ':completion:*' matcher-list '' 'm:{a-z}={A-Z} m:_=\\\ ' '+ l:|=* r:|=*' zstyle ':completion:*' verbose true zstyle ':completion:*:descriptions' format '· %d ·' zstyle ':completion:*:messages' format '· %d ·' zstyle ':completion:*:corrections' format '· %d ·' zstyle ':completion:*:warnings' format '%F{red}no match:%F{default} %d' zstyle ':completion:*' group-name '' # Force menu completion since the input is just a stupid number zstyle ':completion:*:*:kill:*' menu yes zstyle ':completion:*:*:(todo|td*):*:items' menu yes zstyle ':completion:*:*:vi(m|):*' ignored-patterns \ 'a.out|*.o' # source: http://madism.org/~madcoder/dotfiles/zsh/40_completion zstyle ':completion:*:processes' command 'ps -au$USER -o pid,time,cmd|grep -v "ps -au$USER -o pid,time,cmd"' zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#)[ 0-9:]#([^ ]#)*=01;30=01;31=01;38' zstyle ':completion:*:manuals' separate-sections true zstyle ':completion:*:manuals.*' insert-sections true # $hosts is set from the hosts package zstyle ':completion:*' hosts ${(k)hosts} [[ -e $ZCACHEDIR/compdump ]] || zrc_info "Creating completion cache" compinit -C -d $ZCACHEDIR/compdump compdef _hosts sshmount compdef _functions reload # }}} # {{{ Cleanup unalias 'linux:' unfunction zrc_info unfunction xsource unset system distro unset -m 'mime_*' # }}}