tide/functions/_tide_pwd.fish

43 lines
2.0 KiB
Fish
Raw Normal View History

function _tide_pwd
2021-06-02 02:34:42 +03:00
set -l split_pwd (string replace -- $HOME '~' $PWD | string split /)
if not test -w $PWD
2021-09-30 19:17:51 +03:00
set -f icon $tide_pwd_icon_unwritable' '
else if test $PWD = $HOME
2021-09-30 19:17:51 +03:00
set -f icon $tide_pwd_icon_home' '
2021-07-22 20:01:50 +03:00
else
2021-09-30 19:17:51 +03:00
set -f icon $tide_pwd_icon' '
end
2021-08-26 23:47:43 +03:00
# Anchor first and last directories (which may be the same)
2021-10-26 20:50:54 +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
2021-10-26 20:50:54 +03:00
string join / $split_output | string length --visible | read -g pwd_length
2021-06-02 02:34:42 +03:00
i=1 for dir_section in $split_pwd[2..-2]
2021-08-27 00:09:19 +03:00
string join -- / $split_pwd[..$i] | string replace '~' $HOME | read -l parent_dir # Uses i before increment
2021-09-08 06:51:16 +03:00
math $i+1 | read i
2021-01-16 04:33:49 +03:00
2021-05-12 23:13:51 +03:00
# Returns true if any markers exist in dir_section
2021-09-17 21:10:16 +03:00
if test -z false (string split --max 2 " " -- "-o -e $parent_dir/$dir_section/"$tide_pwd_markers)
2021-10-26 20:50:54 +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-11-05 00:26:53 +03:00
string sub --length 1 -- $dir_section | read -l trunc
trunc_len=1 while test $trunc != $dir_section -a (count $parent_dir/$trunc*/) != 1
math $trunc_len+1 | read trunc_len
string sub --length $trunc_len -- $dir_section | read trunc
end
if test $trunc != $dir_section
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
end
2021-10-26 20:50:54 +03:00
string join -- / $split_output
2021-03-02 20:46:40 +03:00
end