Add widget for bash (#105)

Partially solves #37
This commit is contained in:
Denis Isidoro 2019-10-02 12:12:20 -03:00 committed by GitHub
parent d9a7486eb6
commit 4627b5db0b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 16 additions and 9 deletions

View file

@ -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

2
navi
View file

@ -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 "$@"

3
navi.plugin.bash Normal file
View file

@ -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"'

View file

@ -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

View file

@ -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