tide/functions/_tide_pwd.fish

62 lines
1.8 KiB
Fish
Raw Normal View History

2020-05-19 06:03:25 +03:00
function _tide_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
2020-05-19 06:03:25 +03:00
set_color $tide_color_dark_blue
printf '%s' {$tide_pwd_unwritable_icon}' '
set_color $fish_color_normal
end
2020-05-01 06:46:02 +03:00
if test "$splitPwd[1]" != '~'
2020-05-19 06:03:25 +03:00
set_color $tide_color_dark_blue
2020-05-18 20:06:02 +03:00
printf '%s' '/'
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-05-19 06:03:25 +03:00
set_color -o $tide_color_light_blue
2020-05-18 20:06:02 +03:00
printf '%s' "$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
2020-05-19 06:03:25 +03:00
set_color $tide_color_dark_blue
2020-05-18 20:06:02 +03:00
printf '%s' '/'
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-05-19 06:03:25 +03:00
set_color $tide_color_dark_blue
2020-05-18 20:06:02 +03:00
printf '%s' (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-05-19 06:03:25 +03:00
set_color -o $tide_color_light_blue
2020-05-18 20:06:02 +03:00
printf '%s' "$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
2020-05-18 20:06:02 +03:00
printf '%s' ' '
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-19 06:03:25 +03:00
set -l targetLength (math $COLUMNS-$tide_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)
2020-05-19 06:03:25 +03:00
set -l lilac (set_color $tide_color_lilac)
set -l dBlue (set_color $tide_color_dark_blue)
2020-05-02 06:25:59 +03:00
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-18 20:06:02 +03:00
printf '%s' "$colorPwd"
2020-04-03 01:39:10 +03:00
end