From 4627b5db0bbb0bd530891928d9465ede2f72231e Mon Sep 17 00:00:00 2001 From: Denis Isidoro Date: Wed, 2 Oct 2019 12:12:20 -0300 Subject: [PATCH] Add widget for bash (#105) Partially solves #37 --- README.md | 12 ++++++++---- navi | 2 +- navi.plugin.bash | 3 +++ navi.plugin.zsh | 7 +++---- src/main.sh | 1 + 5 files changed, 16 insertions(+), 9 deletions(-) create mode 100644 navi.plugin.bash diff --git a/README.md b/README.md index 38c9b35..be2c3c7 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/navi b/navi index 46a7065..688ea95 100755 --- a/navi +++ b/navi @@ -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 "$@" diff --git a/navi.plugin.bash b/navi.plugin.bash new file mode 100644 index 0000000..64e3d4d --- /dev/null +++ b/navi.plugin.bash @@ -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"' diff --git a/navi.plugin.zsh b/navi.plugin.zsh index be75f17..60c2ea4 100644 --- a/navi.plugin.zsh +++ b/navi.plugin.zsh @@ -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 diff --git a/src/main.sh b/src/main.sh index b95a786..7e9771a 100644 --- a/src/main.sh +++ b/src/main.sh @@ -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