summaryrefslogtreecommitdiff
path: root/home-config/fish/functions/_tide_pwd.fish
diff options
context:
space:
mode:
authorRyan Schanzenbacher <ryan@rschanz.org>2024-04-05 11:57:45 -0400
committerRyan Schanzenbacher <ryan@rschanz.org>2024-04-05 11:57:45 -0400
commitb88d77fb2d0d5028a6f5670695dee6bec129501f (patch)
tree2536b0461d297e647cf07157641c9b1223339adf /home-config/fish/functions/_tide_pwd.fish
parent776a7ca55d2d2c3f396de91db1c6c3c5065012cd (diff)
ahhh sloppy fish, still needs fixing, esp with the vars
Diffstat (limited to 'home-config/fish/functions/_tide_pwd.fish')
-rw-r--r--home-config/fish/functions/_tide_pwd.fish42
1 files changed, 42 insertions, 0 deletions
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 @@
1set_color -o $tide_pwd_color_anchors | read -l color_anchors
2set_color $tide_pwd_color_truncated_dirs | read -l color_truncated
3set -l reset_to_color_dirs (set_color normal -b $tide_pwd_bg_color; set_color $tide_pwd_color_dirs)
4
5set -l unwritable_icon $tide_pwd_icon_unwritable' '
6set -l home_icon $tide_pwd_icon_home' '
7set -l pwd_icon $tide_pwd_icon' '
8
9eval "function _tide_pwd
10 if set -l split_pwd (string replace -r '^$HOME' '~' -- \$PWD | string split /)
11 test -w . && set -f split_output \"$pwd_icon\$split_pwd[1]\" \$split_pwd[2..] ||
12 set -f split_output \"$unwritable_icon\$split_pwd[1]\" \$split_pwd[2..]
13 set split_output[-1] \"$color_anchors\$split_output[-1]$reset_to_color_dirs\"
14 else
15 set -f split_output \"$home_icon$color_anchors~\"
16 end
17
18 string join / -- \$split_output | string length -V | read -g _tide_pwd_len
19
20 i=1 for dir_section in \$split_pwd[2..-2]
21 string join -- / \$split_pwd[..\$i] | string replace '~' $HOME | read -l parent_dir # Uses i before increment
22
23 math \$i+1 | read i
24
25 if path is \$parent_dir/\$dir_section/\$tide_pwd_markers
26 set split_output[\$i] \"$color_anchors\$dir_section$reset_to_color_dirs\"
27 else if test \$_tide_pwd_len -gt \$dist_btwn_sides
28 string match -qr \"(?<trunc>\..|.)\" \$dir_section
29
30 set -l glob \$parent_dir/\$trunc*/
31 set -e glob[(contains -i \$parent_dir/\$dir_section/ \$glob)] # This is faster than inverse string match
32
33 while string match -qr \"^\$parent_dir/\$(string escape --style=regex \$trunc)\" \$glob &&
34 string match -qr \"(?<trunc>\$(string escape --style=regex \$trunc).)\" \$dir_section
35 end
36 test -n \"\$trunc\" && set split_output[\$i] \"$color_truncated\$trunc$reset_to_color_dirs\" &&
37 string join / \$split_output | string length -V | read _tide_pwd_len
38 end
39 end
40
41 string join -- / \"$reset_to_color_dirs\$split_output[1]\" \$split_output[2..]
42end"