summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDenis Isidoro <denisidoro@users.noreply.github.com>2021-08-09 10:47:03 -0300
committerGitHub <noreply@github.com>2021-08-09 10:47:03 -0300
commit9396fd539c596f60714ca6dc9b789e18f36c2f22 (patch)
tree6ed7201d9c64d1537d00e674f250fc1f3f1d06bd
parent3abd3dad6e8a8c0b310233806b85834f5fca6221 (diff)
Widget: fix replacements in case of multiple occurrences
-rw-r--r--docs/navi.cheat6
-rw-r--r--shell/navi.plugin.bash5
-rw-r--r--shell/navi.plugin.zsh5
3 files changed, 12 insertions, 4 deletions
diff --git a/docs/navi.cheat b/docs/navi.cheat
index f83b3e2..94b52b3 100644
--- a/docs/navi.cheat
+++ b/docs/navi.cheat
@@ -29,6 +29,12 @@ navi --tldr "<query>"
navi --cheatsh "<query>"
+% widget
+
+# Load shell widget
+shell="$(basename $SHELL)"; eval "$(navi widget $shell)"
+
+
% help
# Read command-line help text
diff --git a/shell/navi.plugin.bash b/shell/navi.plugin.bash
index e0bbbf6..851b896 100644
--- a/shell/navi.plugin.bash
+++ b/shell/navi.plugin.bash
@@ -12,11 +12,12 @@ _navi_widget() {
if [ -z "${last_command}" ]; then
local -r output="$(_navi_call --print)"
else
- local -r find="$last_command"
+ local -r find="${last_command}_NAVIEND"
local -r replacement="$(_navi_call --print --query "$last_command")"
local output="$input"
if [ -n "$replacement" ]; then
- output="${input//$find/$replacement}"
+ output="${input}_NAVIEND"
+ output="${output//$find/$replacement}"
fi
fi
diff --git a/shell/navi.plugin.zsh b/shell/navi.plugin.zsh
index 99e9598..f94ee77 100644
--- a/shell/navi.plugin.zsh
+++ b/shell/navi.plugin.zsh
@@ -8,7 +8,6 @@ _navi_call() {
_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"
if [ -z "$last_command" ]; then
@@ -20,7 +19,9 @@ _navi_widget() {
fi
if [ -n "$replacement" ]; then
- previous_output="${input//$find/$replacement}"
+ local -r find="${last_command}_NAVIEND"
+ previous_output="${input}_NAVIEND"
+ previous_output="${previous_output//$find/$replacement}"
else
previous_output="$input"
fi