+ # Setup. Create variables holding the formatted content.
+
+ # Current directory in yellow, truncated if necessary (WIDTH is replaced
+ # below).
+ local directory="${yellow}%WIDTH<..<%~%<<${default}"
+ # Minimal information about the VCS, only displayed if there are
+ # unstaged/staged changes.
+ local vcs_staged="${vcs_info_msg_1_}"
+
+ # Information about the VCS in this directory.
+ local vcs="${vcs_info_msg_0_}"
+ # Current time (seconds since epoch) in Hex in bright blue.
+ local seconds="${blue}%B0x$(([##16] EPOCHSECONDS))%b${default}"
+
+ # User name (%n) in bright green.
+ local user="${green}%B%n%b${default}"
+ # Host name (%m) in bright green; underlined if running on a remote system
+ # through SSH.
+ local host="${green}%B%m%b${default}"
+ if [[ -n $SSH_CONNECTION ]]; then
+ host="%U${host}%u"
+ fi
+
+ # Number of background processes in yellow if not zero.
+ local background="%(1j.${yellow}%j${default}.)"
+ # Exit code in bright red in parentheses if not zero.
+ local exitcode="%(?..(${red}%B%?%b${default}%) )"
+ # Prompt symbol, % for normal users, # in red for root.
+ local symbol="%(!.${red}#${default}.%%)"
+
+ # Prefix characters in first and second line.
+ local top_prefix="${blue}%B.-%b${default}"
+ local bottom_prefix="${blue}%B'%b${default}"
+
+ # Combine them to create the prompt.
+
+ local top_left="${vcs_staged}"
+ local top_right="${vcs}(${seconds})"
+
+ local width_top_prefix=${#${(S%%)top_prefix//$~zero/}}
+ local width_top_left=${#${(S%%)top_left//$~zero/}}
+ local width_top_right=${#${(S%%)top_right//$~zero/}}
+
+ # Calculate the maximum width of ${top_left}. -2 are the braces of
+ # ${top_left}, -1 is one separator from ${top_separator} (we want at least
+ # one between left and right parts).
+ local top_left_width_max=$((
+ COLUMNS - $width_top_prefix
+ - $width_top_left - 2
+ - 1
+ - $width_top_right
+ ))
+ # Truncate directory if necessary.
+ top_left="(${directory/WIDTH/${top_left_width_max}})${top_left}"
+ width_top_left=${#${(S%%)top_left//$~zero/}}
+
+ # Calculate the width of the top prompt to fill the middle with "-".
+ local width=$((
+ COLUMNS - width_top_prefix - width_top_left - width_top_right
+ ))
+ local top_separator="%B${blue}${(l:${width}::-:)}%b${default}"
+
+ PROMPT="${top_prefix}${top_left}${top_separator}${top_right}
+${bottom_prefix}${user}@${host} ${background}${symbol} ${exitcode}"
+}
+precmd_functions+=(zshrc_prompt_precmd)
+