fix(bash,zsh): fix quirks on search cancel (#1483)

* fix(bash): preserve the line content on search cancel

In the current implementation for Bash, the line content is lost when
the user cancels the atuin search by pressing ESC, C-g, or Down at the
bottom line.  This is because the line content is set to the empty
string returned by atuin on the cancellation of the search.

In the integrations for other shells, zsh and fish, the empty output
is properly handled so that the line content is preserved.  This patch
makes the behavior in Bash consistent with that in zsh and fish, i.e.,
we do nothing when the atuin search returns an empty output.

* fix(zsh): ignore confusing line `__atuin_accept__:*` on search cancel
This commit is contained in:
Koichi Murase 2024-01-02 17:40:40 +09:00 committed by GitHub
parent d9dab6c92d
commit 7f443588cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 5 deletions

View File

@ -86,6 +86,9 @@ __atuin_history() {
# shellcheck disable=SC2048,SC2086
HISTORY="$(ATUIN_SHELL_BASH=t ATUIN_LOG=error atuin search $* -i -- "${READLINE_LINE}" 3>&1 1>&2 2>&3)"
# We do nothing when the search is canceled.
[[ $HISTORY ]] || return 0
if [[ $HISTORY == __atuin_accept__:* ]]
then
HISTORY=${HISTORY#__atuin_accept__:}

View File

@ -49,12 +49,12 @@ _atuin_search() {
if [[ -n $output ]]; then
RBUFFER=""
LBUFFER=$output
fi
if [[ $LBUFFER == __atuin_accept__:* ]]
then
LBUFFER=${LBUFFER#__atuin_accept__:}
zle accept-line
if [[ $LBUFFER == __atuin_accept__:* ]]
then
LBUFFER=${LBUFFER#__atuin_accept__:}
zle accept-line
fi
fi
}