tide/functions/_lean_pwd.fish

62 lines
1.7 KiB
Fish
Raw Normal View History

function _lean_pwd
2020-05-01 06:46:02 +03:00
set -l splitPwd (string split --no-empty '/' (_shorten_pwd))
set -l splitPwdLength (count $splitPwd)
2020-04-03 01:39:10 +03:00
if not test -w $PWD
set_color $lean_color_dark_blue
2020-05-17 23:47:53 +03:00
printf {$lean_pwd_unwritable_icon}' '
set_color $fish_color_normal
end
2020-05-01 06:46:02 +03:00
if test "$splitPwd[1]" != '~'
2020-04-25 06:56:17 +03:00
set_color $lean_color_dark_blue
2020-05-17 23:47:53 +03:00
printf '/'
2020-04-03 01:39:10 +03:00
set_color $fish_color_normal
2020-04-25 06:56:17 +03:00
end
2020-04-03 01:39:10 +03:00
2020-04-25 06:56:17 +03:00
set_color -o $lean_color_light_blue
2020-05-17 23:47:53 +03:00
printf "$splitPwd[1]"
2020-04-25 06:56:17 +03:00
set_color $fish_color_normal
2020-05-01 06:46:02 +03:00
if test $splitPwdLength -gt 1
set_color $lean_color_dark_blue
2020-05-17 23:47:53 +03:00
printf '/'
set_color $fish_color_normal
2020-04-03 01:39:10 +03:00
end
2020-05-01 06:46:02 +03:00
if test $splitPwdLength -gt 2
2020-04-25 06:56:17 +03:00
set_color $lean_color_dark_blue
2020-05-17 23:47:53 +03:00
printf (string join '/' $splitPwd[2..-2])'/'
2020-04-25 06:56:17 +03:00
set_color $fish_color_normal
2020-04-03 01:39:10 +03:00
end
2020-05-01 06:46:02 +03:00
if test $splitPwdLength -gt 1
2020-04-25 06:56:17 +03:00
set_color -o $lean_color_light_blue
2020-05-17 23:47:53 +03:00
printf "$splitPwd[-1]"
2020-04-25 06:56:17 +03:00
set_color $fish_color_normal
2020-04-03 01:39:10 +03:00
end
2020-05-17 23:47:53 +03:00
printf ' '
2020-04-03 01:39:10 +03:00
end
function _shorten_pwd
2020-05-02 06:25:59 +03:00
set -l pwd (string replace $HOME '~' $PWD)
set -l colorPwd $pwd
2020-05-01 06:46:02 +03:00
set -l splitPwd (string split --no-empty '/' $pwd)
2020-05-02 06:25:59 +03:00
set -l targetLength (math $COLUMNS-$lean_pwd_shorten_margin)
2020-05-02 06:25:59 +03:00
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)
2020-04-03 01:39:10 +03:00
2020-05-01 06:46:02 +03:00
set index (math $index+1)
2020-04-03 01:39:10 +03:00
end
2020-05-17 23:47:53 +03:00
printf "$colorPwd"
2020-04-03 01:39:10 +03:00
end