Skip to content

Commit

Permalink
Add widget for bash (#105)
Browse files Browse the repository at this point in the history
Partially solves #37
  • Loading branch information
denisidoro committed Oct 2, 2019
1 parent d9a7486 commit 4627b5d
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 9 deletions.
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,18 @@ You can use **navi** as a widget to your shell:

This way, your history is correctly populated and you can edit the command as you wish before executing it.

Right now, there's only a widget for zsh. If you want for other shells, please upvote [this issue](https://github.com/denisidoro/navi/issues/37).

In order to use it, add this line to your `.zshrc`-like file:
In order to use it, add this line to your `.bashrc`-like file:
```sh
# bash
source "$(navi widget bash)"

# zsh
source "$(navi widget zsh)"
```

Then, simply hit `Alt+G`.
By default, `Ctrl+G` is assigned to launching **navi**. If you want to change the keybinding, replace the argument of `bind` or `bindkey` in [the widget file](https://github.com/denisidoro/navi/search?q=filename%3Anavi.plugin.*&unscoped_q=filename%3Anavi.plugin.*).

If you want a widget for other shells, please upvote [this issue](https://github.com/denisidoro/navi/issues/37).


### More options
Expand Down
2 changes: 1 addition & 1 deletion navi
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ source "${SCRIPT_DIR}/src/main.sh"
##? full docs
##? Please refer to the README at https://github.com/denisidoro/navi

VERSION="0.10.3"
VERSION="0.11.0"
NAVI_ENV="${NAVI_ENV:-prod}"

opts::eval "$@"
Expand Down
3 changes: 3 additions & 0 deletions navi.plugin.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

bind '"\C-g": " \C-u \C-a\C-k`printf \"\\e\" && navi --print`\e\C-e\C-y\C-a\C-d\C-y\ey\C-h\C-e\C-b"'
7 changes: 3 additions & 4 deletions navi.plugin.zsh
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
local _navi_path=$(dirname $0:A)
_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)"
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
bindkey '^g' _call_navi
1 change: 1 addition & 0 deletions src/main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ handler::widget() {

case "$SH" in
zsh) widget="${SCRIPT_DIR}/navi.plugin.zsh" ;;
bash) widget="${SCRIPT_DIR}/navi.plugin.bash" ;;
*) echoerr "Invalid shell: $SH"; exit 1 ;;
esac

Expand Down

0 comments on commit 4627b5d

Please sign in to comment.