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
|
|
|
|
2021-03-07 21:09:58 +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
|
|
|
|
|
2020-11-24 01:56:52 +03:00
|
|
|
set -l pwdMaxLength (math $COLUMNS -$tide_pwd_truncate_margin)
|
|
|
|
|
2021-03-07 21:09:58 +03:00
|
|
|
set -l i 1
|
|
|
|
for unusedVariable 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-01-26 08:48:34 +03:00
|
|
|
|
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-07 21:09:58 +03:00
|
|
|
# Returns true if any markers exist in splitPwd[$i]
|
|
|
|
if test -z false (string split --max 2 " " -- "-o -e "$parentDir/$splitPwd[$i]/$tide_pwd_markers)
|
2021-01-12 03:23:35 +03:00
|
|
|
set splitPwdForOutput[$i] $colorAnchors$splitPwd[$i]$keepBackgroundColor$colorDirs
|
2021-02-05 02:19:16 +03:00
|
|
|
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-02 20:46:40 +03:00
|
|
|
test $truncationLength -lt (string length -- $splitPwdForLength[$i]) &&
|
|
|
|
set -l truncated (string sub --length $truncationLength -- $splitPwd[$i]) &&
|
|
|
|
test (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
|
|
|
|
|
2021-01-25 18:31:21 +03:00
|
|
|
# All the actual printing
|
|
|
|
if not test -w $PWD
|
|
|
|
printf '%s' $colorDirs $tide_pwd_unwritable_icon' '
|
|
|
|
else if test $PWD = $HOME
|
|
|
|
printf '%s' $colorDirs $tide_pwd_home_icon' '
|
|
|
|
else
|
|
|
|
printf '%s' $colorDirs $tide_pwd_dir_icon' '
|
|
|
|
end
|
|
|
|
|
2021-03-02 20:46:40 +03:00
|
|
|
test "$splitPwd[1]" = '~' || printf '%s' /
|
2021-01-16 07:08:33 +03:00
|
|
|
|
2021-03-02 20:46:40 +03:00
|
|
|
string join -- / $splitPwdForOutput
|
|
|
|
end
|