Skip to content

Commit

Permalink
fix(bash,zsh): fix quirks on search cancel (#1483)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
akinomyoga authored Jan 2, 2024
1 parent d9dab6c commit 7f44358
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
3 changes: 3 additions & 0 deletions atuin/src/shell/atuin.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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__:}
Expand Down
10 changes: 5 additions & 5 deletions atuin/src/shell/atuin.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

1 comment on commit 7f44358

@vercel
Copy link

@vercel vercel bot commented on 7f44358 Jan 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

atuin-docs – ./

atuin-docs-git-main-atuin.vercel.app
atuin-docs-atuin.vercel.app
atuin-docs.vercel.app

Please sign in to comment.