+#
+# Thanks to Adam's prompt for the basic idea of this prompt.
+prompt_precmd() {
+ # Regex to remove elements which take no space. Used to calculate the
+ # width of the top prompt. Thanks to Bart's and Adam's prompt code in
+ # Functions/Prompts/prompt_*_setup.
+ local zero='%([BSUbfksu]|([FB]|){*})'
+
+ # Call vcs_info before every prompt.
+ if [[ -n $RUN_VCS_INFO ]]; then
+ vcs_info
+ else
+ vcs_info_msg_0_=
+ fi
+
+ local width width_left width_right
+ local top_left top_right
+
+ # Display the current time in HEX in bright blue and vcs_info (if used) on
+ # the right in the top prompt.
+ top_right="$vcs_info_msg_0_($blue%B0x$(([##16] EPOCHSECONDS))%b$default)"
+ width_right=${#${(S%%)top_right//$~zero/}}
+ # Remove it if it would get too long.
+ if [[ $(( COLUMNS - 4 - 1 - width_right )) -lt 0 ]]; then
+ top_right=
+ width_right=0
+ fi
+
+ # Display current directory on the left in the top prompt. Truncate the
+ # directory if necessary.
+ width=$(( COLUMNS - 4 - 1 - width_right ))
+ top_left=".-$default%b($yellow%$width<..<%~%<<$default)%B$blue"
+
+ # Calculate the width of the top prompt to fill the middle with "-".
+ width_left=${#${(S%%)top_left//$~zero/}}
+ width_right=${#${(S%%)top_right//$~zero/}}
+ width=$(( COLUMNS - width_left - width_right ))
+
+ PROMPT="$blue%B$top_left${(l:$width::-:)}%b$default$top_right
+$blue%B'%b$default\
+$green%B%n%b$default@$green%B%m%b$default %(1j.$yellow%j$default.)%# \
+%(?..($red%B%?%b$default%) )"
+}
+precmd_functions+=(prompt_precmd)
+
+
+# When screen, tmux, xterm or rxvt is used set the name of the window to the
+# currently running program.
+#
+# When a program is started preexec() sets the window's name to it; when it
+# stops precmd() resets the window's name to 'zsh'. 'fg' is supported and sets
+# the window's name to the resumed job.
+#
+# It works with screen, tmux, xterm and rxvt.
+#
+# If a command is run with sudo or if the shell is running as root then a ! is
+# added at the beginning of the command to make this clear. If a command is
+# running on a different computer with ssh a @ is added at the beginning. If
+# screen/tmux is running on the remote machine instead of @screen @:hostname
+# (or @tmux ..; hostname replaced by the machine's hostname) is displayed.
+# This only works if the .zshrc on the server also uses this command.
+#
+# screen* is necessary as `screen` uses screen.linux for example for a linux
+# console.
+if [[ $TERM == screen* || $TERM == xterm* || $TERM == rxvt* ]]; then
+ # Is set to a non empty value to reset the window name in the next
+ # precmd() call.
+ window_reset=yes
+ # Is set to a non empty value when the shell is running as root.
+ if [[ $UID -eq 0 ]]; then
+ window_root=yes
+ fi
+
+ window_preexec() {
+ # Get the program name with its arguments.
+ local program_name=$1
+
+ # When sudo is used use real program name instead, but with an
+ # exclamation mark at the beginning (handled below).
+ local program_sudo=
+ if [[ $program_name == sudo* ]]; then
+ program_name=${program_name#sudo }
+ program_sudo=yes
+ fi
+
+ # Replace fg with the resumed job name.
+ if [[ $program_name == fg ]]; then
+ program_name=${jobtexts[%+]}
+ elif [[ $program_name == fg\ * ]]; then
+ program_name=${jobtexts[${program_name#fg }]}
+ fi
+
+ # Remove all arguments from the program name.
+ program_name=${program_name%% *}
+
+ # Ignore often used commands which are only running for a very short
+ # time. This prevents a "blinking" name when it's changed to "cd" for
+ # example and then some milliseconds later back to "zsh".
+ [[ $program_name == (cd*|d|ls|l|la|ll|clear|c) ]] && return
+
+ # Change my shortcuts so the real name of the program is displayed.
+ case $program_name in
+ e)
+ program_name=elinks
+ ;;
+ g)
+ program_name=git
+ ;;
+ m)
+ program_name=mutt
+ ;;
+ v)
+ program_name=vim
+ ;;
+ esac
+
+ # Add an exclamation mark at the beginning if running with sudo or if
+ # running zsh as root.
+ if [[ -n $program_sudo || -n $window_root ]]; then
+ program_name=!$program_name
+ fi
+
+ # Add an at mark at the beginning if running through ssh on a
+ # different computer.
+ if [[ -n $SSH_CONNECTION ]]; then
+ program_name="@$program_name"
+
+ # If screen is running in SSH then display "@:hostname" as title
+ # in the term/outer screen.
+ if [[ $program_name == @screen || $program_name == @tmux ]]; then
+ program_name="@:${HOST//.*/}"
+ # Use "@:!hostname" for root screens.
+ elif [[ $program_name == @!screen || $program_name == @!tmux ]]; then
+ program_name="@:!${HOST//.*/}"
+ fi
+ fi
+
+ # Set the window name to the currently running program.
+ window_title "$program_name"
+
+ # Tell precmd() to reset the window name when the program stops.
+ window_reset=yes
+ }
+
+ window_precmd() {
+ # Abort if no window name reset is necessary.
+ [[ -z $window_reset ]] && return
+
+ # Reset the window name to 'zsh'.
+ local name=zsh
+ # If the function was called with an argument then reset the window
+ # name to '.zsh' (used by clear alias).
+ if [[ -n $1 ]]; then
+ name=.zsh
+ fi
+
+ # Prepend prefixes like in window_preexec().
+ if [[ -n $window_root ]]; then
+ name="!$name"
+ fi
+ if [[ -n $SSH_CONNECTION ]]; then
+ name="@$name"
+ fi
+ window_title $name
+
+ # Just reset the name, so no screen reset necessary for the moment.
+ window_reset=
+ }
+
+ # Sets the window title. Works with screen, tmux (which uses screen as
+ # TERM), xterm and rxvt. (V) escapes all non-printable characters. Thanks
+ # to Mikachu in #zsh on Freenode (2010-08-07 17:09 CEST).
+ if [[ $TERM == screen* ]]; then
+ window_title() {
+ print -n "\ek${(V)1}\e\\"
+ }
+ elif [[ $TERM == xterm* || $TERM == rxvt* ]]; then
+ window_title() {
+ print -n "\e]2;${(V)1}\e\\"
+ }
+ else
+ # Fallback if another TERM is used.
+ window_title() { }
+ fi
+
+ # Add the preexec() and precmd() hooks.
+ preexec_functions+=(window_preexec)
+ precmd_functions+=(window_precmd)
+else
+ # Fallback if another TERM is used, necessary to run screen (see below in
+ # "RUN COMMANDS").
+ window_preexec() { }
+fi
+
+
+# COMPLETION SETTINGS
+
+# Load the complist module which provides additional features to completion
+# lists (coloring, scrolling).