tide/functions/_tide_pwd.fish

54 lines
2.3 KiB
Fish
Raw Normal View History

2022-01-05 22:25:32 +03:00
set -l data (
set_color -o $tide_pwd_color_anchors
echo
set_color $tide_pwd_color_truncated_dirs
echo
set_color normal -b $tide_pwd_bg_color; set_color $tide_pwd_color_dirs)
set -l _tide_color_anchors "$data[1]"
set -l _tide_color_truncated_dirs "$data[2]"
set -l _tide_reset_to_color_dirs "$data[3]"
2022-01-05 22:25:32 +03:00
set -l unwritable_icon $tide_pwd_icon_unwritable'\ '
set -l home_icon $tide_pwd_icon_home'\ '
set -l pwd_icon $tide_pwd_icon'\ '
eval "function _tide_pwd
set -l split_pwd (string replace -- $HOME '~' \$PWD | string split /)
if not test -w \$PWD
set -f icon $unwritable_icon
else if test \$PWD = $HOME
set -f icon $home_icon
2021-07-22 20:01:50 +03:00
else
2022-01-05 22:25:32 +03:00
set -f icon $pwd_icon
end
2021-08-26 23:47:43 +03:00
# Anchor first and last directories (which may be the same)
2022-01-05 22:25:32 +03:00
test -n \"\$split_pwd[1]\" && # ~/foo/bar, hightlight ~ OR /foo/bar, hightlight foo not empty string
set -l split_output \"$_tide_reset_to_color_dirs\$icon$_tide_color_anchors\$split_pwd[1]$_tide_reset_to_color_dirs\" \$split_pwd[2..] ||
set -l split_output \"$_tide_reset_to_color_dirs\$icon\" \"$_tide_color_anchors\$split_pwd[2]$_tide_reset_to_color_dirs\" \$split_pwd[3..]
set split_output[-1] \"$_tide_color_anchors\$split_pwd[-1]$_tide_reset_to_color_dirs\"
2021-08-26 23:47:43 +03:00
2022-01-05 22:25:32 +03:00
string join / \$split_output | string length --visible | read -g pwd_length
2021-06-02 02:34:42 +03:00
2022-01-05 22:25:32 +03:00
i=1 for dir_section in \$split_pwd[2..-2]
string join -- / \$split_pwd[..\$i] | string replace '~' $HOME | read -l parent_dir # Uses i before increment
2022-01-05 22:25:32 +03:00
math \$i+1 | read i
2021-01-16 04:33:49 +03:00
if false || for marker in $tide_pwd_markers # false is for if tide_pwd_markers is empty
2022-01-05 22:25:32 +03:00
test -e \$parent_dir/\$dir_section/\$marker && break
end
2022-01-05 22:25:32 +03:00
set split_output[\$i] \"$_tide_color_anchors\$dir_section$_tide_reset_to_color_dirs\"
else if test \$pwd_length -gt \$dist_btwn_sides
2021-12-23 01:59:52 +03:00
set -l trunc
2022-01-05 22:25:32 +03:00
while string match -qr \"(?<trunc>\$trunc.)\" \$dir_section && test (count \$parent_dir/\$trunc*/) != 1
2021-11-05 00:26:53 +03:00
end
2022-01-05 22:25:32 +03:00
test -n \"\$trunc\" && set split_output[\$i] \"$_tide_color_truncated_dirs\$trunc$_tide_reset_to_color_dirs\" &&
string join / \$split_output | string length --visible | read -g pwd_length
2020-11-24 01:56:52 +03:00
end
end
2022-01-05 22:25:32 +03:00
string join -- / \$split_output
end"