diff --git a/.config/zsh/themes/prompt.zsh b/.config/zsh/themes/prompt.zsh index 8ecda82..2419cc1 100644 --- a/.config/zsh/themes/prompt.zsh +++ b/.config/zsh/themes/prompt.zsh @@ -89,9 +89,28 @@ else add-zsh-hook precmd vcs_info fi +# Reduce directory elements to first letter until directory path is reasonably +# short. Never shrink first element. +function _shrunkpwd() +{ + local dir=${(D)PWD} + local -i maxwidth=$(( ${COLUMNS} / 3 )) + + local -a shortdir=(${(s:/:)dir}) + for index in {2..${#shortdir}}; do + if [[ ${#${(j:/:)shortdir}} -gt ${maxwidth} ]]; then + shortdir[index]=${shortdir[index][1]} + fi + done + + local out=${(j:/:)shortdir} + [[ ${out[1]} != '~' ]] && out[1]="/${out[1]}" + print -n ${out} +} + setopt PROMPT_SUBST PROMPT="%B%F{${zsh_theme_colours[prompt]}}${showuser}%b"'${vcs_info_msg_0_}'"%B%F{${zsh_theme_colours[prompt]}}%#%f%b " -RPROMPT="%F{${zsh_theme_colours[minor]}}%(?..[%B%F{${zsh_theme_colours[highlight]}}%?%b%F{${zsh_theme_colours[minor]}}] )%4~%f" +RPROMPT="%F{${zsh_theme_colours[minor]}}%(?..[%B%F{${zsh_theme_colours[highlight]}}%?%b%F{${zsh_theme_colours[minor]}}] )"'$(_shrunkpwd)'"%f" }