+# Load aliases and similar functions also used by other shells.
+if [[ -f ~/.shell/aliases ]]; then
+ . ~/.shell/aliases
+fi
+
+# Make sure aliases are expanded when using sudo.
+alias sudo='sudo '
+
+# Global aliases for often used redirections.
+alias -g E='2>&1'
+alias -g N='>/dev/null'
+alias -g EN='2>/dev/null'
+alias -g L='2>&1 | less'
+alias -g LS='2>&1 | less -S' # -S prevents wrapping of long lines
+alias -g D='2>&1 | colordiff | less'
+# Global aliases for often used commands.
+alias -g A='| awk'
+alias -g A1="| awk '{ print \$1 }'"
+alias -g A2="| awk '{ print \$2 }'"
+alias -g A3="| awk '{ print \$3 }'"
+alias -g G='| grep'
+alias -g H='| head'
+alias -g P='| perl'
+alias -g S='| sort'
+alias -g T='| tail'
+alias -g U='| uniq'
+
+# Make going up directories simple.
+alias -g ...='../..'
+alias -g ....='../../..'
+alias -g .....='../../../..'
+
+# If the window naming feature is used (see above) then use ".zsh" (leading
+# dot) as title name after running clear so it's clear to me that the window
+# is empty. I open so much windows that I don't know in which I have something
+# important. This helps me to remember which windows are empty (I run clear
+# after I finished my work in a window).
+if [[ -n $zshrc_window_reset ]]; then
+ alias clear='clear; zshrc_window_reset=yes; zshrc_window_precmd reset'
+fi
+
+
+# CUSTOM COMMANDS
+
+# Display all branches (except stash) in gitk but only 200 commits as this is
+# much faster. Also put in the background and disown. Thanks to drizzd in #git
+# on Freenode (2010-04-03 17:55 CEST).
+(( $+commands[gitk] )) && gitk() {
+ command gitk --max-count=200 --branches --remotes --tags "$@" &
+ disown %command
+}
+# Same for tig (except the disown part as it's no GUI program).
+(( $+commands[tig] )) && tig() {
+ command tig --max-count=200 --branches --remotes --tags "$@"
+}
+
+# Choose the "best" PDF viewer available. Also setup completion for `pdf`.
+if (( $+commands[katarakt] )); then
+ pdf() {
+ command katarakt "$@" 2>/dev/null &
+ disown %command
+ }
+ # No completion for katarakt yet.
+ compdef pdf=xpdf
+elif (( $+commands[xpdf] )); then
+ pdf() {
+ command xpdf "$@" 2>/dev/null &
+ disown %command
+ }
+ compdef pdf=xpdf
+elif (( $+commands[zathura] )); then
+ pdf() {
+ command zathura "$@" 2>/dev/null &
+ disown %command
+ }
+ # No completion for zathura yet.
+ compdef pdf=xpdf
+fi
+
+
+# OS SPECIFIC SETTINGS
+
+if [[ $OSTYPE == linux* ]]; then
+ # Settings when creating Debian packages.
+ export DEBEMAIL=simon@ruderich.org
+ export DEBFULLNAME='Simon Ruderich'
+fi
+
+
+# LOAD ADDITIONAL CONFIGURATION FILES
+
+# Configuration options for rc.local.
+
+# Multiplexer to use. By default GNU screen is used. Possible values: screen,
+# tmux and empty (no multiplexer).
+zshrc_use_multiplexer=screen
+# Additional arguments for fortune.
+zshrc_fortune_arguments=()
+
+source_config ~/.zsh/rc.local
+
+
+# RUN COMMANDS
+
+# Make sure the multiplexer is available. Otherwise the exec terminates our
+# session.
+if [[ -n $zshrc_use_multiplexer ]]; then
+ if ! (( $+commands[$zshrc_use_multiplexer] )); then
+ echo "Multiplexer '$zshrc_use_multiplexer' not found." >&2
+ zshrc_use_multiplexer=
+ fi
+fi
+
+# If not already in screen or tmux, reattach to a running session or create a
+# new one. This also starts screen/tmux on a remote server when connecting
+# through ssh.
+if [[ $TERM != dumb && $TERM != dialup && $TERM != linux
+ && -z $STY && -z $TMUX ]]; then
+ # Get running detached sessions.
+ if [[ $zshrc_use_multiplexer = screen ]]; then
+ session=$(screen -list | grep 'Detached' | awk '{ print $1; exit }')
+ elif [[ $zshrc_use_multiplexer = tmux ]]; then
+ session=$(tmux list-sessions 2>/dev/null \
+ | sed '/(attached)$/ d; s/^\([0-9]\{1,\}\).*$/\1/; q')
+ fi
+
+ # As we exec later we have to set the title here.
+ if [[ $zshrc_use_multiplexer = screen ]]; then
+ zshrc_window_preexec screen
+ elif [[ $zshrc_use_multiplexer = tmux ]]; then
+ zshrc_window_preexec tmux