Colorize truncated dirs

This commit is contained in:
Ilan Cosman 2020-05-01 20:25:59 -07:00
parent be781a786f
commit 5f5a18b91d
2 changed files with 14 additions and 9 deletions

View File

@ -38,19 +38,23 @@ function lean_pwd
end
function _shorten_pwd
set -l pwd (string replace $HOME '~' (pwd))
set -l pwd (string replace $HOME '~' $PWD)
set -l colorPwd $pwd
set -l splitPwd (string split --no-empty '/' $pwd)
set -l targetLength (math $COLUMNS-$lean_pwd_shorten_margin)
set -l pwdLength (string length $pwd)
set -l shortenPwdLength (math $COLUMNS-$lean_pwd_shorten_margin)
set -l index 2
while test (string length $pwd) -gt $targetLength
set -l currentPart $splitPwd[$index]
set -l currentPartFirstLetter (string sub -l 1 $currentPart)
set pwd (string replace $currentPart $currentPartFirstLetter $pwd)
set -l lilac (set_color $lean_color_lilac)
set -l dBlue (set_color $lean_color_dark_blue)
set colorPwd (string replace $currentPart "$lilac"$currentPartFirstLetter"$dBlue" $colorPwd)
set -l index 1
while test $pwdLength -gt $shortenPwdLength
set splitPwd[$index] (string sub -l 1 $splitPwd[$index])
set pwd (string join '/' $splitPwd)
set pwdLength (string length $pwd)
set index (math $index+1)
end
echo $pwd
echo $colorPwd
end

View File

@ -26,6 +26,7 @@ function lean_install
set -U lean_color_light_blue 00AFFF
set -U lean_color_dark_blue 0087AF
set -U lean_color_gold D7AF00
set -U lean_color_lilac 8787AF
# ---------------Pwd---------------
set -U lean_pwd_shorten_margin 5
set -U lean_pwd_unwritable_icon '' # Lock