+# Set the prompt. A two line prompt is used. On the top left the current
+# working directory is displayed, on the right vcs_info (if available) and the
+# current time in hex. On the bottom left current user name and host is shown,
+# the exit code of the last command if it wasn't 0, the number of running jobs
+# if not 0.
+#
+# The prompt is in green and blue to make easily detectable, the error exit
+# code in red and bold and the job count in yellow.
+#
+# 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%) )"
+}
+add-zsh-hook precmd prompt_precmd
+
+
+# When screen, xterm or rxvt is used set the name of the window to the
+# currently running program.