diff --git a/README.md b/README.md index ead7ef05..38c9b352 100644 --- a/README.md +++ b/README.md @@ -52,12 +52,39 @@ brew install denisidoro/tools/navi Alternatively, you can `git clone` this repository and run `make`: ```sh -git clone --depth 1 http://github.com/denisidoro/navi /opt/navi +git clone --depth 1 https://github.com/denisidoro/navi /opt/navi cd /opt/navi sudo make install # install fzf: https://github.com/junegunn/fzf ``` + +### Using oh-my-zsh + +Make sure that your oh-my-zsh `$ZSH_CUSTOM` directory is configured, then clone navi into the plugins directory. +```sh +export ZSH_CUSTOM='/path/to/.zsh' +plugins_dir="$ZSH_CUSTOM/plugins" +mkdir -p "$plugins_dir" +cd "$plugins_dir" +git clone https://github.com/denisidoro/navi +``` + +Then, add it to the oh-my-zsh plugin array: +``` +# Sample ~/.zshrc +ZSHCFG="$HOME/.zsh" +ZSH="$ZSHCFG/oh-my-zsh" +ZSH_CUSTOM="$ZSHCFG" +plugins=(docker tmux fzf navi) +# ... +source "$ZSH/oh-my-zsh.sh" +``` + +Finally, you can use it as a [shell widget](#shell-widget). + +This method has the advantage of not requiring root to install and disadvantage of not allowing you to invoke the script by calling `navi` (unless you add an alias to it or copy it to a folder in `$PATH`). + Upgrading --------- @@ -65,6 +92,7 @@ Upgrading - brew: `brew update; brew reinstall navi` - git: `cd /opt/navi && sudo make update` +- oh-my-zsh: `cd "$(navi home)" && git pull` Usage ----- diff --git a/navi.plugin.zsh b/navi.plugin.zsh new file mode 100644 index 00000000..be75f179 --- /dev/null +++ b/navi.plugin.zsh @@ -0,0 +1,13 @@ +local _navi_path=$(dirname $0:A) + +_call_navi() { + local buff="$BUFFER" + zle kill-whole-line + local cmd="$(NAVI_USE_FZF_ALL_INPUTS=true $_navi_path/navi --print <> /dev/tty)" + zle -U "${buff}${cmd}" + # zle accept-line +} + +zle -N _call_navi + +bindkey '\eg' _call_navi diff --git a/shell/widget.zsh b/shell/widget.zsh deleted file mode 100644 index 2a1a83df..00000000 --- a/shell/widget.zsh +++ /dev/null @@ -1,11 +0,0 @@ -_call_navi() { - local buff="$BUFFER" - zle kill-whole-line - local cmd="$(NAVI_USE_FZF_ALL_INPUTS=true navi --print <> /dev/tty)" - zle -U "${buff}${cmd}" - # zle accept-line -} - -zle -N _call_navi - -bindkey '\eg' _call_navi \ No newline at end of file diff --git a/src/main.sh b/src/main.sh index 88e49a44..b95a7861 100644 --- a/src/main.sh +++ b/src/main.sh @@ -97,7 +97,7 @@ handler::widget() { local widget case "$SH" in - zsh) widget="${SCRIPT_DIR}/shell/widget.zsh" ;; + zsh) widget="${SCRIPT_DIR}/navi.plugin.zsh" ;; *) echoerr "Invalid shell: $SH"; exit 1 ;; esac @@ -144,4 +144,4 @@ main() { handler::main ;; esac -} \ No newline at end of file +}