From 5a2cbe0147b7dcedcfaa665723a62c3bef56dcc8 Mon Sep 17 00:00:00 2001 From: Alin Panaitiu Date: Sun, 8 Mar 2020 18:15:06 +0200 Subject: [PATCH] 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