Skip to content

Instantly share code, notes, and snippets.

@Nezteb
Created May 5, 2023 00:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Nezteb/81e8f6b78036894a28a4a40772bdda54 to your computer and use it in GitHub Desktop.
Save Nezteb/81e8f6b78036894a28a4a40772bdda54 to your computer and use it in GitHub Desktop.
A shell hack for restoring basic up/down arrow functionality with atuin while still using its database instead of vanilla shell history until it's implemented natively: https://github.com/ellie/atuin/issues/798
export ATUIN_ARROW_INDEX=-1
upArrow() {
export ATUIN_ARROW_INDEX=$(( ATUIN_ARROW_INDEX + 1))
COMMAND=$(atuin search --limit 1 --offset $ATUIN_ARROW_INDEX | cut -f2)
LBUFFER="$COMMAND"
return
}
downArrow() {
export ATUIN_ARROW_INDEX=$(( ATUIN_ARROW_INDEX - 1))
if [ $ATUIN_ARROW_INDEX -lt 0 ]; then
export ATUIN_ARROW_INDEX=-1
LBUFFER=""
return
fi
COMMAND=$(atuin search --limit 1 --offset $ATUIN_ARROW_INDEX | cut -f2)
LBUFFER="$COMMAND"
return
}
returnKey() {
export ATUIN_ARROW_INDEX=-1
zle accept-line
}
zle -N upArrow
zle -N downArrow
zle -N returnKey
bindkey '\eOA' upArrow
bindkey '\eOB' downArrow
bindkey '^M' returnKey
# TODO: The below ctrl+c intfercepting doesn't work in ZSH for some reason
ctrlC() {
echo "ctrl c"
export ATUIN_ARROW_INDEX=-1
}
zle -N ctrlC
bindkey '^C' ctrlC
trap "ctrlC" INT TERM
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment