+__vcs_get_prompt_path_components()
+{
+ # return formatted path components (prefix branch postfix) given
+ # the repository root and the branch.
+
+ # shortcut: if there are no arguments, return a default prompt
+ if [ -z "${1:-}" ]; then
+ pwdnamed="%${_PROMPT_PATH_MAXLEN}<..<%~%<<"
+ pwdnamed="${(%)pwdnamed}"
+ echo "$pwdnamed"
+ return
+ fi
+
+ local reporoot branch
+ reporoot="${1%%/}"
+ branch="$2"
+
+ # replace named directories in the PWD, we need thi for the proper component
+ # count later
+ local pwdnamed="%~"
+ pwdnamed="${(%)pwdnamed}"
+
+ # store paths in arrays for component count calculation
+ typeset -la apwd apwdnamed areporoot
+ apwd=(${(s:/:)PWD})
+ apwdnamed=(${(s:/:)pwdnamed})
+ areporoot=(${(s:/:)reporoot})
+
+ # get the number of leading and trailing path components. Since we're using
+ # %~ later and then /home/madduck suddenly becomes ~, which is 1, not
+ # 2 components, we calculate the leading component count by using the named
+ # path and the number of post components
+ local precomps postcomps
+ postcomps=$(($#apwd - $#areporoot))
+ precomps=$(($#apwdnamed - $postcomps))
+
+ local postfix
+ if (( $postcomps > 0 )); then
+ postfix="%${postcomps}~"
+ postfix="${(%)postfix}"
+ fi
+
+ # we don't want the prompt to get too long, so keep the total prompt length
+ # under $_PROMPT_PATH_MAXLEN (25), but ensure that the prefix is not shorter
+ # than $_PROMPT_PATH_MINLEN (10), no matter what
+ local prelen minlen prefix
+ prelen=$((${_PROMPT_PATH_MAXLEN:-25} - $#branch - $#postfix))
+ minlen=${_PROMPT_PATH_MINLEN:-10}
+ (( $prelen < $minlen )) && prelen=$minlen
+ prefix="%${prelen}<..<%-${precomps}~%<<"
+ prefix="${(%)prefix}"
+
+ echo "$prefix" "$branch" "$postfix"
+}
+