Zsh: Shrink PWD in RPROMPT dynamically
This commit is contained in:
parent
025c3ae0ff
commit
a2a261ddbe
|
@ -89,9 +89,28 @@ else
|
||||||
add-zsh-hook precmd vcs_info
|
add-zsh-hook precmd vcs_info
|
||||||
fi
|
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
|
setopt PROMPT_SUBST
|
||||||
|
|
||||||
PROMPT="%B%F{${zsh_theme_colours[prompt]}}${showuser}%b"'${vcs_info_msg_0_}'"%B%F{${zsh_theme_colours[prompt]}}%#%f%b "
|
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"
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user