2020-05-20 20:05:33 +03:00
|
|
|
function _tide_item_pwd
|
2020-05-20 19:16:02 +03:00
|
|
|
set -l splitPwd (string split --no-empty '/' (_truncate_pwd))
|
2020-05-01 06:46:02 +03:00
|
|
|
set -l splitPwdLength (count $splitPwd)
|
2020-04-03 01:39:10 +03:00
|
|
|
|
2020-04-28 23:46:40 +03:00
|
|
|
if not test -w $PWD
|
2020-05-19 21:25:17 +03:00
|
|
|
set_color $tide_pwd_color_mid_dirs
|
2020-05-19 06:03:25 +03:00
|
|
|
printf '%s' {$tide_pwd_unwritable_icon}' '
|
2020-04-28 23:46:40 +03:00
|
|
|
set_color $fish_color_normal
|
|
|
|
end
|
|
|
|
|
2020-05-01 06:46:02 +03:00
|
|
|
if test "$splitPwd[1]" != '~'
|
2020-05-19 21:25:17 +03:00
|
|
|
set_color $tide_pwd_color_mid_dirs
|
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 21:25:17 +03:00
|
|
|
set_color -o $tide_pwd_color_end_dirs
|
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 21:25:17 +03:00
|
|
|
set_color $tide_pwd_color_mid_dirs
|
2020-05-18 20:06:02 +03:00
|
|
|
printf '%s' '/'
|
2020-04-23 01:19:58 +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 2
|
2020-05-19 21:25:17 +03:00
|
|
|
set_color $tide_pwd_color_mid_dirs
|
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 21:25:17 +03:00
|
|
|
set_color -o $tide_pwd_color_end_dirs
|
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
|
|
|
|
|
2020-05-20 19:16:02 +03:00
|
|
|
function _truncate_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-22 20:24:12 +03:00
|
|
|
set -l maxLength (math $COLUMNS-$tide_pwd_truncate_margin)
|
2020-04-23 01:19:58 +03:00
|
|
|
|
2020-05-22 20:24:12 +03:00
|
|
|
if test (string length $pwd) -gt $maxLength
|
2020-05-22 01:05:11 +03:00
|
|
|
for dir in $splitPwd[2..-2]
|
2020-05-22 20:24:12 +03:00
|
|
|
set -l dirTruncated (string sub -l 1 $dir)
|
|
|
|
if test $dirTruncated = '.'
|
|
|
|
set dirTruncated (string sub -l 2 $dir)
|
|
|
|
end
|
|
|
|
|
|
|
|
set pwd (string replace $dir $dirTruncated $pwd)
|
2020-05-02 06:25:59 +03:00
|
|
|
|
2020-05-22 22:46:05 +03:00
|
|
|
set -l colorTruncatedDirs (set_color $tide_pwd_color_truncated_dirs)
|
|
|
|
set -l colorMidDirs (set_color $tide_pwd_color_mid_dirs)
|
|
|
|
set colorPwd (string replace $dir "$colorTruncatedDirs"$dirTruncated"$colorMidDirs" $colorPwd)
|
2020-04-03 01:39:10 +03:00
|
|
|
|
2020-05-22 20:24:12 +03:00
|
|
|
if test (string length $pwd) -lt $maxLength
|
2020-05-22 01:05:11 +03:00
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
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
|