tide/functions/_tide_pwd.fish

35 lines
1.4 KiB
Fish
Raw Normal View History

2020-06-06 20:40:14 +03:00
function _tide_pwd
set -l truncatedPwd $_tide_pwd
set -l colorDirs (set_color $tide_pwd_color_dirs)
set -g _tide_pwd_output $colorDirs$_tide_pwd
2020-06-06 20:40:14 +03:00
if not test -w $PWD
2020-07-01 03:34:57 +03:00
if test -n "$tide_pwd_unwritable_icon"
set _tide_pwd_output "$tide_pwd_unwritable_icon "$_tide_pwd_output
end
2020-06-06 20:40:14 +03:00
end
2020-06-07 19:40:42 +03:00
set -l truncatedList '.' $_tide_split_pwd
2020-06-06 20:40:14 +03:00
for dir in $_tide_split_pwd
if contains $dir $_tide_pwd_anchors
2020-06-25 05:47:15 +03:00
set _tide_pwd_output (string replace $dir (set_color -o $tide_pwd_color_anchors)$dir(set_color normal -b $tide_pwd_bg_color) $_tide_pwd_output)
2020-06-06 20:40:14 +03:00
else
2020-06-06 21:57:43 +03:00
if test (string length $truncatedPwd) -gt $_tide_pwd_max_length
2020-06-07 19:40:42 +03:00
set -l dirTruncated $dir
set -l truncationLength 1
while contains $dirTruncated $truncatedList
set dirTruncated (string sub -l $truncationLength $dir)
set truncationLength (math $truncationLength+1)
2020-06-06 20:40:14 +03:00
end
2020-06-07 19:40:42 +03:00
set -a truncatedList $dirTruncated
2020-06-06 20:40:14 +03:00
set truncatedPwd (string replace $dir $dirTruncated $truncatedPwd)
2020-06-08 06:14:15 +03:00
set _tide_pwd_output (string replace $dir (set_color $tide_pwd_color_truncated_dirs)$dirTruncated $_tide_pwd_output)
2020-06-06 20:40:14 +03:00
end
end
end
set _tide_pwd_output (string replace -a '/' $colorDirs'/' $_tide_pwd_output)
2020-06-06 20:40:14 +03:00
end