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"
+ # Setup. Create variables holding the formatted content.
+
+ # Current directory in yellow, truncated if necessary (WIDTH is replaced
+ # below).
+ local directory="${yellow}%WIDTH<..<%~%<<${default}"
+
+ # 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.
+ local host="${green}%B%m%b${default}"
+ # Number of background processes in yellow.
+ local background="%(1j.${yellow}%j${default}.)"
+ # Exit code in bright red if not zero.
+ local exitcode="%(?..(${red}%B%?%b${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_right="${vcs}(${seconds})"
+
+ local width_top_prefix=${#${(S%%)top_prefix//$~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 - 2 - 1 - $width_top_right
+ ))
+ # Truncate directory if necessary.
+ local top_left="(${directory/WIDTH/${top_left_width_max}})"
+ local width_top_left=${#${(S%%)top_left//$~zero/}}
# 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%) )"
+ 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}%# ${exitcode}"
}
precmd_functions+=(prompt_precmd)