tide/functions/_tide_pwd.fish

43 lines
2.0 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-05-06 23:43:22 +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' '
2022-01-05 22:25:32 +03:00
eval "function _tide_pwd
if set -l split_pwd (string replace -r '^$HOME' '~' -- \$PWD | string split /)
2022-05-06 23:43:22 +03:00
test -w . && set -f split_output \"$pwd_icon\$split_pwd[1]\" \$split_pwd[2..] ||
set -f split_output \"$unwritable_icon\$split_pwd[1]\" \$split_pwd[2..]
2022-05-07 03:34:16 +03:00
set split_output[-1] \"$color_anchors\$split_output[-1]$reset_to_color_dirs\"
2021-07-22 20:01:50 +03:00
else
2022-05-07 03:34:16 +03:00
set -f split_output \"$home_icon$color_anchors~\"
end
2021-08-26 23:47:43 +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
2022-07-30 00:39:08 +03:00
if path is \$parent_dir/\$dir_section/\$tide_pwd_markers
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
string match -qr \"(?<trunc>\..|.)\" \$dir_section
2023-07-14 02:27:06 +03:00
2023-07-14 02:50:50 +03:00
set -l glob \$parent_dir/\$trunc*/
set -e glob[(contains -i \$parent_dir/\$dir_section/ \$glob)] # This is faster than inverse string match
2023-07-14 02:27:06 +03:00
while string match -qr \"^\$parent_dir/\$(string escape --style=regex \$trunc)\" \$glob &&
string match -qr \"(?<trunc>\$(string escape --style=regex \$trunc).)\" \$dir_section
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-05-06 23:33:32 +03:00
string join -- / \"$reset_to_color_dirs\$split_output[1]\" \$split_output[2..]
2022-01-05 22:25:32 +03:00
end"