+# Better viewer for info pages .. just pipe everything into less.
+info() {
+ command info "$@" 2>/dev/null | less
+}
+
+
+# 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 != 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
+ fi
+
+ # Create a new session if none is running.
+ if [[ -z $session ]]; then
+ if [[ $zshrc_use_multiplexer = screen ]]; then
+ exec screen
+ elif [[ $zshrc_use_multiplexer = tmux ]]; then
+ exec tmux
+ fi
+ # Reattach to a running session.
+ else
+ if [[ $zshrc_use_multiplexer = screen ]]; then
+ exec screen -r $session
+ elif [[ $zshrc_use_multiplexer = tmux ]]; then
+ exec tmux attach-session -t $session
+ fi
+ fi
+fi
+
+# Colorize stderr in bold red. Very useful when looking for errors.
+if [[ $LD_PRELOAD != *libcoloredstderr.so* ]]; then
+ # coloredstderr found, use it.
+ if [[ -f ~/.zsh/libcoloredstderr.so ]]; then
+ export LD_PRELOAD="$HOME/.zsh/libcoloredstderr.so:$LD_PRELOAD"
+ export COLORED_STDERR_FDS=2,
+ export COLORED_STDERR_PRE=$'\033[91m' # bright red
+ export COLORED_STDERR_IGNORED_BINARIES=/usr/bin/tset
+ # Use the fallback solution.
+ #
+ # Thanks to http://gentoo-wiki.com/wiki/Zsh for the basic script and
+ # Mikachu in #zsh on Freenode (2010-03-07 04:03 CET) for some improvements
+ # (-r, printf). It's not yet perfect and doesn't work with su and git for
+ # example, but it can handle most interactive output quite well (even with
+ # no trailing new line) and in cases it doesn't work, the E alias can be
+ # used as workaround.
+ #
+ # Moved in the "run commands" section to prevent one unnecessary zsh
+ # process when starting GNU screen/tmux (see above).
+ else
+ exec 2>>(while read -r -k -u 0 line; do
+ printf '\e[91m%s\e[0m' "$line"
+ print -n $'\0'
+ done &)
+ fi
+fi
+
+# Display possible log messages from ~/.xinitrc (if `xmessage` wasn't
+# installed). No race condition as xinitrc has finished before a shell is
+# executed and only one shell is started on login.
+if [[ -f ~/.xinitrc.errors ]]; then
+ echo "${fg_bold[red]}xinitrc failed!${fg_bold[default]}"
+ echo
+ cat ~/.xinitrc.errors
+ rm ~/.xinitrc.errors
+ echo
+fi
+
+# Run the following programs every 4 hours (and when zsh starts).
+PERIOD=14400
+periodic() {
+ # Display fortunes.
+ (( $+commands[fortune] )) && fortune -ac "${zshrc_fortune_arguments[@]}"
+ # Display reminders.
+ (( $+commands[rem] )) && [[ -f ~/.reminders ]] && rem -h