tide/functions/_tide_item_pwd.fish

44 lines
2.2 KiB
Fish
Raw Normal View History

2020-05-20 20:05:33 +03:00
function _tide_item_pwd
2020-12-26 19:42:21 +03:00
set -l colorDirs (set_color $tide_pwd_color_dirs || echo)
set -l colorAnchors (set_color -o $tide_pwd_color_anchors || echo)
set -l keepBackgroundColor (set_color normal -b $tide_pwd_bg_color || echo)
set -l colorTruncatedDirs (set_color $tide_pwd_color_truncated_dirs || echo)
2020-11-24 01:56:52 +03:00
set -l splitPwd (string replace -- $HOME '~' $PWD | string split --no-empty '/')
set -l splitPwdForLength $splitPwd
set -l splitPwdForOutput $splitPwd
# Anchor first and last directories
set splitPwdForOutput[1] $colorAnchors"$splitPwd[1]"$keepBackgroundColor$colorDirs
set splitPwdForOutput[-1] $colorAnchors"$splitPwd[-1]"$keepBackgroundColor$colorDirs
2021-05-05 06:26:58 +03:00
pwdMaxLength=(math $COLUMNS -$tide_pwd_truncate_margin) i=1 for dirSection in $splitPwd[2..-2]
2021-02-05 02:36:54 +03:00
set -l parentDir (string join -- '/' $splitPwd[1..$i] | string replace '~' $HOME) # Use i from before increment
2021-02-05 02:36:54 +03:00
set i (math $i + 1) # This keeps us from using seq
2021-01-16 04:33:49 +03:00
2021-03-16 19:05:34 +03:00
# Returns true if any markers exist in dirSection
if test -z false (string split --max 2 " " -- "-o -e "$parentDir/$dirSection/$tide_pwd_markers)
set splitPwdForOutput[$i] $colorAnchors$dirSection$keepBackgroundColor$colorDirs
else if test (string join -- '/' $splitPwdForLength | string length) -gt $pwdMaxLength
2021-02-05 02:36:54 +03:00
while set -l truncationLength (math $truncationLength + 1) &&
2021-03-16 19:05:34 +03:00
set -l truncated (string sub --length $truncationLength -- $dirSection) &&
test $truncated != $dirSection -a (count $parentDir/$truncated*/) -gt 1
2020-11-24 01:56:52 +03:00
end
2021-01-12 03:23:35 +03:00
2021-01-10 19:56:46 +03:00
set splitPwdForLength[$i] $truncated
2021-01-12 03:23:35 +03:00
set splitPwdForOutput[$i] $colorTruncatedDirs$truncated$keepBackgroundColor$colorDirs
2020-11-24 01:56:52 +03:00
end
end
# Printing logic
test "$splitPwd[1]" = '~' || set splitPwdForOutput[1] '/'$splitPwdForOutput[1]
2021-01-25 18:31:21 +03:00
if not test -w $PWD
_tide_print_item pwd $colorDirs$tide_pwd_unwritable_icon' ' (string join -- / $splitPwdForOutput)
2021-01-25 18:31:21 +03:00
else if test $PWD = $HOME
_tide_print_item pwd $colorDirs$tide_pwd_home_icon' ' (string join -- / $splitPwdForOutput)
2021-01-25 18:31:21 +03:00
else
_tide_print_item pwd $colorDirs$tide_pwd_dir_icon' ' (string join -- / $splitPwdForOutput)
2021-01-25 18:31:21 +03:00
end
2021-03-02 20:46:40 +03:00
end