tide/functions/lean_pwd.fish

61 lines
1.8 KiB
Fish
Raw Normal View History

2020-04-03 01:39:10 +03:00
function lean_pwd
2020-04-13 22:57:21 +03:00
set -l pwdSplit (string split "/" (_shorten_pwd))
set -l pwdSplitLength (count $pwdSplit)
2020-04-03 01:39:10 +03:00
if test $pwdSplit[1] != "~"
set_color -o $lean_color_light_blue
2020-04-03 01:39:10 +03:00
echo -n "/"
set_color $fish_color_normal
else
set_color -o $lean_color_light_blue
2020-04-03 01:39:10 +03:00
echo -n $pwdSplit[1]
set_color $fish_color_normal
if test $pwdSplitLength -gt 1
set_color $lean_color_dark_blue
2020-04-03 01:39:10 +03:00
echo -n "/"
set_color $fish_color_normal
end
end
set_color $lean_color_dark_blue
2020-04-03 01:39:10 +03:00
echo -n (string join "/" $pwdSplit[2..-2])
if test $pwdSplitLength -gt 2
echo -n "/"
end
set_color $fish_color_normal
set_color -o $lean_color_light_blue
2020-04-03 01:39:10 +03:00
if test $pwdSplitLength -gt 1
echo -n $pwdSplit[-1]
end
set_color $fish_color_normal
end
function _shorten_pwd
2020-04-13 22:57:21 +03:00
set -l fish_prompt_pwd_dir_length 0
set -l lengthPromptPwd (string length (prompt_pwd))
set -l shortenPwdLength (math $COLUMNS-$lean_shorten_pwd_margin)
2020-04-03 01:39:10 +03:00
if test $lengthPromptPwd -gt $shortenPwdLength
2020-04-13 22:57:21 +03:00
set -l smallestAbsoluteDiff $lengthPromptPwd
2020-04-03 01:39:10 +03:00
for promptPwdDirLength in 4 5 6 7 8 9 10 0
2020-04-13 22:57:21 +03:00
set -l fish_prompt_pwd_dir_length $promptPwdDirLength
set -l lengthPromptPwd (string length (prompt_pwd))
2020-04-03 01:39:10 +03:00
if test $lengthPromptPwd -lt $shortenPwdLength
2020-04-13 22:57:21 +03:00
set -l absoluteDiff (math "abs($shortenPwdLength-$lengthPromptPwd)")
2020-04-03 01:39:10 +03:00
if test $absoluteDiff -lt $smallestAbsoluteDiff
2020-04-13 22:57:21 +03:00
set -l smallestAbsoluteDiff $absoluteDiff
set -l bestPromptPwdDirLength $promptPwdDirLength
2020-04-03 01:39:10 +03:00
end
end
end
2020-04-13 22:57:21 +03:00
set -l fish_prompt_pwd_dir_length $bestPromptPwdDirLength
2020-04-03 01:39:10 +03:00
end
echo (prompt_pwd)
end