Skip to content

Commit

Permalink
Merge pull request #101 from alxbl/omzsh-plugin
Browse files Browse the repository at this point in the history
Thanks for making this project, it's really cool! I'd been looking for something like this for a while.
I noticed that your shell widget is pretty much stand-alone and I wanted to be able to use navi directly as an [oh-my-zsh][1] plugin, so I added a few things to the widget and moved it to the root of the repository so that the repo can be cloned straight into the `plugins` folder and detected when added in the plugin array.

I think it should be similarly simple with `fish`, but I'm not too familiar with that shell, so I'll leave it to someone else. The `navi.plugin.zsh` file should still be sourcable as a widget for people not using oh-my-zsh, so technically the `shell/` directory could be removed and `navi widget`updated to use the new file.

## What's included
- oh-my-zsh plugin
- install documentation
- no PATH modification required when used with OMZ
- Added bonus: #51 is kind of unofficially addressed by this (assuming one uses OMZ)

## Future Work
- Pre-filter using `$BUFFER` when hitting `Alt+G` to get something similar to `navi query`
- Update `navi widget zsh` to use `navi.plugin.zsh`

Let me know what you think. I'm working on a few cheatsheets, and will open PRs for those as they become ready.

Cheers,
Alex

[1]: https://github.com/robbyrussell/oh-my-zsh
  • Loading branch information
denisidoro committed Oct 2, 2019
2 parents 0c960fc + 022aee2 commit d9a7486
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 14 deletions.
30 changes: 29 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,47 @@ 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
---------

**navi** is being actively developed and you might want to upgrade it once in a while. Please follow the instruction below depending on the installation method used:

- brew: `brew update; brew reinstall navi`
- git: `cd /opt/navi && sudo make update`
- oh-my-zsh: `cd "$(navi home)" && git pull`

Usage
-----
Expand Down
13 changes: 13 additions & 0 deletions navi.plugin.zsh
Original file line number Diff line number Diff line change
@@ -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
11 changes: 0 additions & 11 deletions shell/widget.zsh

This file was deleted.

4 changes: 2 additions & 2 deletions src/main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -144,4 +144,4 @@ main() {
handler::main
;;
esac
}
}

0 comments on commit d9a7486

Please sign in to comment.