summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDenis Isidoro <denisidoro@users.noreply.github.com>2021-08-07 15:57:22 -0300
committerGitHub <noreply@github.com>2021-08-07 15:57:22 -0300
commita36c26f92262118b47c35ce09867e557797822cf (patch)
treee3da54168aada34e2243527bbd328e447b5ebdc9
parent425ce805306898dab29aef994ee96b1e19cd8f57 (diff)
Close widget on single ESC (#597)
Fixes #546 and #553
-rwxr-xr-xscripts/fix2
-rw-r--r--shell/navi.plugin.bash40
-rw-r--r--shell/navi.plugin.zsh45
-rw-r--r--tests/core.bash4
4 files changed, 46 insertions, 45 deletions
diff --git a/scripts/fix b/scripts/fix
index 02b6a7a..71f60cb 100755
--- a/scripts/fix
+++ b/scripts/fix
@@ -32,5 +32,7 @@ cargo clippy || true
_commit
log::note "dot code beautify..."
find scripts -type f | xargs -I% dot code beautify % || true
+dot code beautify "${NAVI_HOME}/shell/navi.plugin.bash" || true
+dot code beautify "${NAVI_HOME}/shell/navi.plugin.zsh" || true
dot code beautify "${NAVI_HOME}/tests/core.bash" || true
dot code beautify "${NAVI_HOME}/tests/run" || true
diff --git a/shell/navi.plugin.bash b/shell/navi.plugin.bash
index bef4fc3..e0bbbf6 100644
--- a/shell/navi.plugin.bash
+++ b/shell/navi.plugin.bash
@@ -1,35 +1,35 @@
#!/usr/bin/env bash
_navi_call() {
- local result="$(navi "$@" </dev/tty)"
- if [ -z "${result}" ]; then
- result="$(navi --print </dev/tty)"
- fi
- printf "%s" "$result"
+ local result="$(navi "$@" </dev/tty)"
+ printf "%s" "$result"
}
_navi_widget() {
- local -r input="${READLINE_LINE}"
- local -r last_command="$(echo "${input}" | navi fn widget::last_command)"
+ local -r input="${READLINE_LINE}"
+ local -r last_command="$(echo "${input}" | navi fn widget::last_command)"
- if [ -z "${last_command}" ]; then
- local -r output="$(FZF_OVERRIDES="${FZF_OVERRIDES:-} --no-select-1" _navi_call --print)"
- else
- local -r find="$last_command"
- local -r replacement="$(_navi_call --print --query "${last_command}")"
- local -r output="${input//$find/$replacement}"
- fi
+ if [ -z "${last_command}" ]; then
+ local -r output="$(_navi_call --print)"
+ else
+ local -r find="$last_command"
+ local -r replacement="$(_navi_call --print --query "$last_command")"
+ local output="$input"
+ if [ -n "$replacement" ]; then
+ output="${input//$find/$replacement}"
+ fi
+ fi
- READLINE_LINE="$output"
- READLINE_POINT=${#READLINE_LINE}
+ READLINE_LINE="$output"
+ READLINE_POINT=${#READLINE_LINE}
}
_navi_widget_legacy() {
- _navi_call --print
+ _navi_call --print
}
-if [ ${BASH_VERSION:0:1} -lt 4 ]; then
- bind '"\C-g": " \C-b\C-k \C-u`_navi_widget_legacy`\e\C-e\C-a\C-y\C-h\C-e\e \C-y\ey\C-x\C-x\C-f"'
+if [ ${BASH_VERSION:0:1} -lt 4 ]; then
+ bind '"\C-g": " \C-b\C-k \C-u`_navi_widget_legacy`\e\C-e\C-a\C-y\C-h\C-e\e \C-y\ey\C-x\C-x\C-f"'
else
- bind -x '"\C-g": _navi_widget'
+ bind -x '"\C-g": _navi_widget'
fi \ No newline at end of file
diff --git a/shell/navi.plugin.zsh b/shell/navi.plugin.zsh
index 7164e59..99e9598 100644
--- a/shell/navi.plugin.zsh
+++ b/shell/navi.plugin.zsh
@@ -1,35 +1,34 @@
#!/usr/bin/env zsh
_navi_call() {
- local result="$(navi "$@" </dev/tty)"
- if [ -z "${result}" ]; then
- result="$(navi --print </dev/tty)"
- fi
- printf "%s" "$result"
+ local result="$(navi "$@" </dev/tty)"
+ printf "%s" "$result"
}
_navi_widget() {
- local -r input="${LBUFFER}"
- local -r last_command="$(echo "${input}" | navi fn widget::last_command)"
- local find="$last_command"
- local replacement="$last_command"
+ local -r input="${LBUFFER}"
+ local -r last_command="$(echo "${input}" | navi fn widget::last_command)"
+ local find="$last_command"
+ local replacement="$last_command"
- if [ -z "${last_command}" ]; then
- replacement="$(FZF_OVERRIDES="${FZF_OVERRIDES:-} --no-select-1" _navi_call --print)"
- elif [ "${LASTWIDGET}" = "_navi_widget" ] && [ "$input" = "$previous_output" ]; then
- find="$input"
- replacement="$(_navi_call --print --query "${previous_last_command:-$last_command}")"
- else
- replacement="$(_navi_call --print --best-match --query "${last_command}")"
- fi
+ if [ -z "$last_command" ]; then
+ replacement="$(_navi_call --print)"
+ elif [ "$LASTWIDGET" = "_navi_widget" ] && [ "$input" = "$previous_output" ]; then
+ replacement="$(_navi_call --print --query "$last_command")"
+ else
+ replacement="$(_navi_call --print --best-match --query "$last_command")"
+ fi
- previous_last_command="$last_command"
- previous_output="${input//$find/$replacement}"
+ if [ -n "$replacement" ]; then
+ previous_output="${input//$find/$replacement}"
+ else
+ previous_output="$input"
+ fi
- zle kill-whole-line
- LBUFFER="${previous_output}"
- region_highlight=("P0 100 bold")
- zle redisplay
+ zle kill-whole-line
+ LBUFFER="${previous_output}"
+ region_highlight=("P0 100 bold")
+ zle redisplay
}
zle -N _navi_widget
diff --git a/tests/core.bash b/tests/core.bash
index ea102f0..d9fd80b 100644
--- a/tests/core.bash
+++ b/tests/core.bash
@@ -41,13 +41,13 @@ test::run() {
}
test::_escape() {
- tr '\n' "$NEWLINE_CHAR" | sed -E "s/[\s$(printf "$NEWLINE_CHAR") ]+$//g"
+ tr '\n' "$NEWLINE_CHAR" | sed -E "s/[\s$(printf "$NEWLINE_CHAR") ]+$//g"
}
test::equals() {
local -r actual="$(cat)"
local -r expected="$(echo "${1:-}")"
-
+
local -r actual2="$(echo "$actual" | test::_escape)"
local -r expected2="$(echo "$expected" | test::_escape)"