Tweak path algorithm in Zsh prompt

Reduce allowed element width to increase probability of unshortened last
element.
This commit is contained in:
tastytea 2022-04-27 15:01:59 +02:00
parent cd8244faa4
commit b252ce4ec5
Signed by: tastytea
SSH Key Fingerprint: SHA256:FBkvrOlhq5use1XEttyUGT4bUTDVA1ar9SgIc9P03cM

View File

@ -29,7 +29,7 @@ function prompt_tastytea_shrunkpwd() {
# Maybe shorten all elements but the first and last
local -a short_dir=(${(s:/:)dir})
local -i allowed_element_width=$(( ${max_width} / ${#short_dir} - 1 ))
local -i allowed_element_width=$(( ( ${max_width} - ${#short_dir[1]} - ${#short_dir[-1]} ) / ${#short_dir} ))
for index in {2..$(( ${#short_dir} - 1 ))}; do
if [[ ${#short_dir[index]} -gt ${allowed_element_width} ]]; then
[[ ${#${(j:/:)short_dir}} -le ${max_width} ]] && break