From b88d77fb2d0d5028a6f5670695dee6bec129501f Mon Sep 17 00:00:00 2001 From: Ryan Schanzenbacher Date: Fri, 5 Apr 2024 11:57:45 -0400 Subject: ahhh sloppy fish, still needs fixing, esp with the vars --- home-config/fish/functions/_tide_pwd.fish | 42 +++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 home-config/fish/functions/_tide_pwd.fish (limited to 'home-config/fish/functions/_tide_pwd.fish') diff --git a/home-config/fish/functions/_tide_pwd.fish b/home-config/fish/functions/_tide_pwd.fish new file mode 100644 index 0000000..5447dd4 --- /dev/null +++ b/home-config/fish/functions/_tide_pwd.fish @@ -0,0 +1,42 @@ +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) + +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 + if set -l split_pwd (string replace -r '^$HOME' '~' -- \$PWD | string split /) + 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..] + set split_output[-1] \"$color_anchors\$split_output[-1]$reset_to_color_dirs\" + else + set -f split_output \"$home_icon$color_anchors~\" + end + + string join / -- \$split_output | string length -V | read -g _tide_pwd_len + + 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 + + math \$i+1 | read i + + if path is \$parent_dir/\$dir_section/\$tide_pwd_markers + set split_output[\$i] \"$color_anchors\$dir_section$reset_to_color_dirs\" + else if test \$_tide_pwd_len -gt \$dist_btwn_sides + string match -qr \"(?\..|.)\" \$dir_section + + set -l glob \$parent_dir/\$trunc*/ + set -e glob[(contains -i \$parent_dir/\$dir_section/ \$glob)] # This is faster than inverse string match + + while string match -qr \"^\$parent_dir/\$(string escape --style=regex \$trunc)\" \$glob && + string match -qr \"(?\$(string escape --style=regex \$trunc).)\" \$dir_section + end + test -n \"\$trunc\" && set split_output[\$i] \"$color_truncated\$trunc$reset_to_color_dirs\" && + string join / \$split_output | string length -V | read _tide_pwd_len + end + end + + string join -- / \"$reset_to_color_dirs\$split_output[1]\" \$split_output[2..] +end" -- cgit v1.2.3