Widget: fix replacements in case of multiple occurrences

This commit is contained in:
Denis Isidoro 2021-08-09 10:47:03 -03:00 committed by GitHub
parent 3abd3dad6e
commit 9396fd539c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 4 deletions

View File

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

View File

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

View File

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