From 7f443588cf591b53ff77614d42ddc7823f20394f Mon Sep 17 00:00:00 2001 From: Koichi Murase Date: Tue, 2 Jan 2024 17:40:40 +0900 Subject: [PATCH] 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 --- atuin/src/shell/atuin.bash | 3 +++ atuin/src/shell/atuin.zsh | 10 +++++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/atuin/src/shell/atuin.bash b/atuin/src/shell/atuin.bash index 6257d2c9..d05859d2 100644 --- a/atuin/src/shell/atuin.bash +++ b/atuin/src/shell/atuin.bash @@ -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__:} diff --git a/atuin/src/shell/atuin.zsh b/atuin/src/shell/atuin.zsh index 7091382a..491ff9ac 100644 --- a/atuin/src/shell/atuin.zsh +++ b/atuin/src/shell/atuin.zsh @@ -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 }