From a8b7e972ead8df887f06537ccc017fe556f43fd3 Mon Sep 17 00:00:00 2001 From: Ryan Schanzenbacher Date: Fri, 12 Apr 2024 23:09:46 -0400 Subject: added zoxide helper plugin --- home-config/fish/functions/__zoxide_cd.fish | 6 ++++++ home-config/fish/functions/__zoxide_pwd.fish | 7 +++++++ home-config/fish/functions/__zoxide_z.fish | 13 +++++++++++++ home-config/fish/functions/__zoxide_z_complete.fish | 15 +++++++++++++++ home-config/fish/functions/__zoxide_zi.fish | 4 ++++ 5 files changed, 45 insertions(+) create mode 100644 home-config/fish/functions/__zoxide_cd.fish create mode 100644 home-config/fish/functions/__zoxide_pwd.fish create mode 100644 home-config/fish/functions/__zoxide_z.fish create mode 100644 home-config/fish/functions/__zoxide_z_complete.fish create mode 100644 home-config/fish/functions/__zoxide_zi.fish (limited to 'home-config/fish/functions') diff --git a/home-config/fish/functions/__zoxide_cd.fish b/home-config/fish/functions/__zoxide_cd.fish new file mode 100644 index 0000000..d5a8b2b --- /dev/null +++ b/home-config/fish/functions/__zoxide_cd.fish @@ -0,0 +1,6 @@ +function __zoxide_cd + __zoxide_cd_internal $argv + if test "$_ZO_ECHO" = 1 + __zoxide_pwd + end +end diff --git a/home-config/fish/functions/__zoxide_pwd.fish b/home-config/fish/functions/__zoxide_pwd.fish new file mode 100644 index 0000000..49f9357 --- /dev/null +++ b/home-config/fish/functions/__zoxide_pwd.fish @@ -0,0 +1,7 @@ +function __zoxide_pwd + if test "$_ZO_RESOLVE_SYMLINKS" = 1 + builtin pwd -P + else + builtin pwd -L + end +end diff --git a/home-config/fish/functions/__zoxide_z.fish b/home-config/fish/functions/__zoxide_z.fish new file mode 100644 index 0000000..bb24f69 --- /dev/null +++ b/home-config/fish/functions/__zoxide_z.fish @@ -0,0 +1,13 @@ +function __zoxide_z + set --local argc (count $argv) + if test $argc -eq 0 + __zoxide_cd $HOME + else if test "$argv" = - + __zoxide_cd - + else if test $argc -eq 1 -a -d $argv[1] + __zoxide_cd $argv[1] + else + set --local result (command zoxide query --exclude (__zoxide_pwd) -- $argv) + and __zoxide_cd $result + end +end diff --git a/home-config/fish/functions/__zoxide_z_complete.fish b/home-config/fish/functions/__zoxide_z_complete.fish new file mode 100644 index 0000000..9e6196f --- /dev/null +++ b/home-config/fish/functions/__zoxide_z_complete.fish @@ -0,0 +1,15 @@ +function __zoxide_z_complete + set --local tokens (commandline --current-process --tokenize) + set --local curr_tokens (commandline --cut-at-cursor --current-process --tokenize) + + if test (count $tokens) -le 2 -a (count $curr_tokens) -eq 1 + # If there are < 2 arguments, use `cd` completions. + __fish_complete_directories "$tokens[2]" '' + else if test (count $tokens) -eq (count $curr_tokens) + # If the last argument is empty, use interactive selection. + set --local query $tokens[2..-1] + set --local result (zoxide query --interactive -- $query) + commandline --current-process "$tokens[1] "(string escape $result) + commandline --function repaint + end +end diff --git a/home-config/fish/functions/__zoxide_zi.fish b/home-config/fish/functions/__zoxide_zi.fish new file mode 100644 index 0000000..35837ac --- /dev/null +++ b/home-config/fish/functions/__zoxide_zi.fish @@ -0,0 +1,4 @@ +function __zoxide_zi + set --local result (command zoxide query --interactive -- $argv) + and __zoxide_cd $result +end -- cgit v1.2.3