tide/functions/_tide_pwd.fish

44 lines
2.1 KiB
Fish
Raw Normal View History

2022-01-15 19:25:15 +03:00
set_color -o $tide_pwd_color_anchors | read -l color_anchors
set_color $tide_pwd_color_truncated_dirs | read -l color_truncated
set -l reset_to_color_dirs (set_color normal -b $tide_pwd_bg_color; set_color $tide_pwd_color_dirs)
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
2022-01-19 19:24:38 +03:00
if set -l split_pwd (string replace -r '^$HOME' '~' \$PWD | string split /)
2022-01-25 22:16:29 +03:00
test -w . && set -f icon $pwd_icon || set -f icon $unwritable_icon
2021-07-22 20:01:50 +03:00
else
2022-01-19 19:18:14 +03:00
set -f icon $home_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
2022-01-06 00:50:08 +03:00
set -l split_output \"$reset_to_color_dirs\$icon$color_anchors\$split_pwd[1]$reset_to_color_dirs\" \$split_pwd[2..] ||
set -l split_output \"$reset_to_color_dirs\$icon\" \"$color_anchors\$split_pwd[2]$reset_to_color_dirs\" \$split_pwd[3..]
2022-03-12 03:09:15 +03:00
set split_output[-1] \"$color_anchors\$split_output[-1]$reset_to_color_dirs\"
2021-08-26 23:47:43 +03:00
2022-01-26 20:35:35 +03:00
string join / \$split_output | string length -V | read -g _tide_pwd_len
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-06 00:50:08 +03:00
set split_output[\$i] \"$color_anchors\$dir_section$reset_to_color_dirs\"
2022-01-26 20:35:35 +03:00
else if test \$_tide_pwd_len -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-06 00:50:08 +03:00
test -n \"\$trunc\" && set split_output[\$i] \"$color_truncated\$trunc$reset_to_color_dirs\" &&
2022-01-26 20:35:35 +03:00
string join / \$split_output | string length -V | read _tide_pwd_len
2020-11-24 01:56:52 +03:00
end
end
2022-01-05 22:25:32 +03:00
string join -- / \$split_output
end"