summaryrefslogtreecommitdiffstats
path: root/fish/conf.d
diff options
context:
space:
mode:
authorChristoph Schlosser <cschlosser@google.com>2025-06-17 07:23:30 +0000
committerChristoph Schlosser <cschlosser@google.com>2025-06-17 07:23:30 +0000
commitd0e2daac6b87e2977b3782170f138434b22b8a62 (patch)
tree30be7cf6acbf260daf5f72f78885d7a2f3c780b8 /fish/conf.d
parentf311f52b11ac29e3bddf0d0f47316cd06fa0f208 (diff)
downloaddots-d0e2daac6b87e2977b3782170f138434b22b8a62.tar.gz
Add z plugin
Diffstat (limited to 'fish/conf.d')
-rw-r--r--fish/conf.d/_z-make-portable.fish6
-rw-r--r--fish/conf.d/z.fish63
2 files changed, 69 insertions, 0 deletions
diff --git a/fish/conf.d/_z-make-portable.fish b/fish/conf.d/_z-make-portable.fish
new file mode 100644
index 0000000..fea1758
--- /dev/null
+++ b/fish/conf.d/_z-make-portable.fish
@@ -0,0 +1,6 @@
+# Don't use set -U here
+# set -U stores the actual value of $HOME in the fish_variables file
+# which is tracked in the dotfiles repo.
+# This makes it non-portable.
+set -x Z_DATA $HOME/.local/share/z/data
+set -xp Z_EXCLUDE $HOME
diff --git a/fish/conf.d/z.fish b/fish/conf.d/z.fish
new file mode 100644
index 0000000..59c960f
--- /dev/null
+++ b/fish/conf.d/z.fish
@@ -0,0 +1,63 @@
+if test -z "$Z_DATA"
+ if test -z "$XDG_DATA_HOME"
+ set -U Z_DATA_DIR "$HOME/.local/share/z"
+ else
+ set -U Z_DATA_DIR "$XDG_DATA_HOME/z"
+ end
+ set -U Z_DATA "$Z_DATA_DIR/data"
+end
+
+if test ! -e "$Z_DATA"
+ if test ! -e "$Z_DATA_DIR"
+ mkdir -p -m 700 "$Z_DATA_DIR"
+ end
+ touch "$Z_DATA"
+end
+
+if test -z "$Z_CMD"
+ set -U Z_CMD z
+end
+
+set -U ZO_CMD "$Z_CMD"o
+
+if test ! -z $Z_CMD
+ function $Z_CMD -d "jump around"
+ __z $argv
+ end
+end
+
+if test ! -z $ZO_CMD
+ function $ZO_CMD -d "open target dir"
+ __z -d $argv
+ end
+end
+
+if not set -q Z_EXCLUDE
+ set -U Z_EXCLUDE "^$HOME\$"
+else if contains $HOME $Z_EXCLUDE
+ # Workaround: migrate old default values to a regex (see #90).
+ set Z_EXCLUDE (string replace -r -- "^$HOME\$" '^'$HOME'$$' $Z_EXCLUDE)
+end
+
+# Setup completions once first
+__z_complete
+
+function __z_on_variable_pwd --on-variable PWD
+ __z_add
+end
+
+function __z_uninstall --on-event z_uninstall
+ functions -e __z_on_variable_pwd
+ functions -e $Z_CMD
+ functions -e $ZO_CMD
+
+ if test ! -z "$Z_DATA"
+ printf "To completely erase z's data, remove:\n" >/dev/stderr
+ printf "%s\n" "$Z_DATA" >/dev/stderr
+ end
+
+ set -e Z_CMD
+ set -e ZO_CMD
+ set -e Z_DATA
+ set -e Z_EXCLUDE
+end