From e59305162532284b94816a85c9fcac1ed0a0402e Mon Sep 17 00:00:00 2001 From: Alin Panaitiu Date: Sun, 8 Mar 2020 14:29:43 +0200 Subject: [PATCH 1/4] Add fish integration --- README.md | 13 +++++++++++++ functions/z.fish | 12 ++++++++++++ init.fish | 14 ++++++++++++++ 3 files changed, 39 insertions(+) create mode 100644 functions/z.fish create mode 100644 init.fish diff --git a/README.md b/README.md index 916d00a..e2c0ab8 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,13 @@ A cd command that learns your habits +## Table of contents + +- [Installing `zoxide`](#installing-zoxide) +- [Adding `zoxide` to your shell](#adding-zoxide-to-your-shell) + + [zsh](#zsh) + + [fish](#fish) + ## Introduction `zoxide` is a new `cd` alternative inspired by [`z`](https://github.com/rupa/z) and [`z.lua`](https://github.com/skywind3000/z.lua). It keeps track of the directories you use most frequently, and uses a ranking algorithm to navigate to the best match. @@ -78,6 +85,12 @@ alias zq="zoxide query" alias zr="zoxide remove" ``` +#### fish +Using [fisher](https://github.com/jorgebucaran/fisher): +```sh +fisher add ajeetdsouza/zoxide +``` + ## Configuration ### Environment variables diff --git a/functions/z.fish b/functions/z.fish new file mode 100644 index 0000000..542b5d1 --- /dev/null +++ b/functions/z.fish @@ -0,0 +1,12 @@ +function z + if test (count $argv) -gt 0 + set _Z_RESULT (zoxide query $argv) + switch "$_Z_RESULT" + case 'query: *' + cd (string sub -s 8 -- "$_Z_RESULT") + case '*' + echo "$_Z_RESULT" + end + commandline -f repaint + end +end diff --git a/init.fish b/init.fish new file mode 100644 index 0000000..1350a64 --- /dev/null +++ b/init.fish @@ -0,0 +1,14 @@ +function zoxide-add --on-event fish_prompt + if command -q zoxide + zoxide add + end +end + +if command -q zoxide + abbr -a zi "z -i" + abbr -a za "zoxide add" + abbr -a zq "zoxide query" + abbr -a zr "zoxide remove" + + bind \ez 'z -i' +end From 5a2cbe0147b7dcedcfaa665723a62c3bef56dcc8 Mon Sep 17 00:00:00 2001 From: Alin Panaitiu Date: Sun, 8 Mar 2020 18:15:06 +0200 Subject: [PATCH 2/4] Changes based on PR review --- README.md | 21 ++++++++++++++------- functions/z.fish | 7 +++++-- init.fish | 26 +++++++++++++++----------- 3 files changed, 34 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index e2c0ab8..a210334 100644 --- a/README.md +++ b/README.md @@ -4,13 +4,6 @@ A cd command that learns your habits -## Table of contents - -- [Installing `zoxide`](#installing-zoxide) -- [Adding `zoxide` to your shell](#adding-zoxide-to-your-shell) - + [zsh](#zsh) - + [fish](#fish) - ## Introduction `zoxide` is a new `cd` alternative inspired by [`z`](https://github.com/rupa/z) and [`z.lua`](https://github.com/skywind3000/z.lua). It keeps track of the directories you use most frequently, and uses a ranking algorithm to navigate to the best match. @@ -91,6 +84,20 @@ Using [fisher](https://github.com/jorgebucaran/fisher): fisher add ajeetdsouza/zoxide ``` +Using [omf](https://github.com/oh-my-fish/oh-my-fish): +```sh +omf install https://github.com/ajeetdsouza/zoxide +``` + +To enable key bindings you have to set the universal variable `ZOXIDE_KEY_BINDINGS` to 1 and restart the shell. +```fish +set -U ZOXIDE_KEY_BINDINGS 1 +``` + +| Keybinding | Action | +| ---------- | -------------------------------------------------------------------------------- | +| Alt+z / +z | Launch Zoxide in interactive mode | + ## Configuration ### Environment variables diff --git a/functions/z.fish b/functions/z.fish index 542b5d1..cc54b8d 100644 --- a/functions/z.fish +++ b/functions/z.fish @@ -4,9 +4,12 @@ function z switch "$_Z_RESULT" case 'query: *' cd (string sub -s 8 -- "$_Z_RESULT") + commandline -f repaint case '*' - echo "$_Z_RESULT" + if test -n "$_Z_RESULT" + echo "$_Z_RESULT" + end end - commandline -f repaint end end + diff --git a/init.fish b/init.fish index 1350a64..9f88bc1 100644 --- a/init.fish +++ b/init.fish @@ -1,14 +1,18 @@ function zoxide-add --on-event fish_prompt - if command -q zoxide - zoxide add + zoxide add +end + +set -q ZOXIDE_KEY_BINDINGS +or set -U ZOXIDE_KEY_BINDINGS 0 + +abbr -a zi "z -i" +abbr -a za "zoxide add" +abbr -a zq "zoxide query" +abbr -a zr "zoxide remove" + +if set -q ZOXIDE_KEY_BINDINGS; and test "$ZOXIDE_KEY_BINDINGS" -eq 1 + bind \ez 'z -i' + if bind -M insert >/dev/null 2>/dev/null + bind -M insert \ez 'z -i' end end - -if command -q zoxide - abbr -a zi "z -i" - abbr -a za "zoxide add" - abbr -a zq "zoxide query" - abbr -a zr "zoxide remove" - - bind \ez 'z -i' -end From e6879744c5106f0aa245e086a5c9c50ba7ed6eee Mon Sep 17 00:00:00 2001 From: Alin Panaitiu Date: Sun, 8 Mar 2020 18:19:56 +0200 Subject: [PATCH 3/4] Remove key bindings --- README.md | 9 --------- init.fish | 10 ---------- 2 files changed, 19 deletions(-) diff --git a/README.md b/README.md index a210334..4467a04 100644 --- a/README.md +++ b/README.md @@ -89,15 +89,6 @@ Using [omf](https://github.com/oh-my-fish/oh-my-fish): omf install https://github.com/ajeetdsouza/zoxide ``` -To enable key bindings you have to set the universal variable `ZOXIDE_KEY_BINDINGS` to 1 and restart the shell. -```fish -set -U ZOXIDE_KEY_BINDINGS 1 -``` - -| Keybinding | Action | -| ---------- | -------------------------------------------------------------------------------- | -| Alt+z / +z | Launch Zoxide in interactive mode | - ## Configuration ### Environment variables diff --git a/init.fish b/init.fish index 9f88bc1..7e5462f 100644 --- a/init.fish +++ b/init.fish @@ -2,17 +2,7 @@ function zoxide-add --on-event fish_prompt zoxide add end -set -q ZOXIDE_KEY_BINDINGS -or set -U ZOXIDE_KEY_BINDINGS 0 - abbr -a zi "z -i" abbr -a za "zoxide add" abbr -a zq "zoxide query" abbr -a zr "zoxide remove" - -if set -q ZOXIDE_KEY_BINDINGS; and test "$ZOXIDE_KEY_BINDINGS" -eq 1 - bind \ez 'z -i' - if bind -M insert >/dev/null 2>/dev/null - bind -M insert \ez 'z -i' - end -end From f6822c06ad8a2a00b1b29e60fd3e53f71d941d7f Mon Sep 17 00:00:00 2001 From: Alin Panaitiu Date: Sun, 8 Mar 2020 20:23:00 +0200 Subject: [PATCH 4/4] Small fixes --- README.md | 2 +- functions/z.fish | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 4467a04..71cd9d3 100644 --- a/README.md +++ b/README.md @@ -84,7 +84,7 @@ Using [fisher](https://github.com/jorgebucaran/fisher): fisher add ajeetdsouza/zoxide ``` -Using [omf](https://github.com/oh-my-fish/oh-my-fish): +Using [oh-my-fish](https://github.com/oh-my-fish/oh-my-fish): ```sh omf install https://github.com/ajeetdsouza/zoxide ``` diff --git a/functions/z.fish b/functions/z.fish index cc54b8d..1e05067 100644 --- a/functions/z.fish +++ b/functions/z.fish @@ -6,9 +6,7 @@ function z cd (string sub -s 8 -- "$_Z_RESULT") commandline -f repaint case '*' - if test -n "$_Z_RESULT" - echo "$_Z_RESULT" - end + echo -n "$_Z_RESULT" end end end