Last active
March 21, 2024 18:47
-
-
Save alextremblay/316d2beede9acd1a29d45d9d32dd310f to your computer and use it in GitHub Desktop.
atuin up-arrow mod
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# replace the default: | |
[[ -f ~/.bash-preexec.sh ]] && source ~/.bash-preexec.sh | |
eval "$(atuin init bash)" | |
# with this: | |
[[ -f ~/.bash-preexec.sh ]] && source ~/.bash-preexec.sh | |
eval "$(atuin init bash --disable-up-arrow)" | |
export ATUIN_ARROW_INDEX=-1 | |
export ATUIN_CYCLE_MODE=0 | |
__atuin__up_arrow() { | |
if [[ $ATUIN_CYCLE_MODE -eq 0 && -n "$READLINE_LINE" ]]; then | |
# execute traditional atuin_history up arrow function, interactive backwards prefix search or whatever | |
__atuin_history --shell-up-key-binding | |
return | |
fi | |
export ATUIN_ARROW_INDEX=$(( ATUIN_ARROW_INDEX + 1)) | |
export ATUIN_CYCLE_MODE=1 | |
HISTORY=$(atuin search --cmd-only --filter-mode host --limit 1 --offset $ATUIN_ARROW_INDEX) | |
READLINE_LINE=${HISTORY} | |
READLINE_POINT=${#READLINE_LINE} | |
return | |
} | |
__atuin__down_arrow() { | |
export ATUIN_ARROW_INDEX=$(( ATUIN_ARROW_INDEX - 1)) | |
if [[ $ATUIN_ARROW_INDEX -lt 0 ]]; then | |
__atuin__reset_arrow | |
HISTORY="" | |
else | |
HISTORY=$(atuin search --cmd-only --filter-mode host --limit 1 --offset $ATUIN_ARROW_INDEX) | |
fi | |
READLINE_LINE=${HISTORY} | |
READLINE_POINT=${#READLINE_LINE} | |
return | |
} | |
__atuin__reset_arrow() { | |
export ATUIN_ARROW_INDEX=-1 | |
export ATUIN_CYCLE_MODE=0 | |
} | |
bind -x '"\e[A": __atuin__up_arrow' | |
bind -x '"\eOA": __atuin__up_arrow' | |
bind -x '"\e[B": __atuin__down_arrow' | |
bind -x '"\eOB": __atuin__down_arrow' | |
precmd_functions+=(__atuin__reset_arrow) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
eval "$(atuin init zsh --disable-up-arrow)" | |
export ATUIN_ARROW_INDEX=-1 | |
export ATUIN_CYCLE_MODE=0 | |
__atuin__up_arrow() { | |
if [[ $ATUIN_CYCLE_MODE -eq 0 && -n "$READLINE_LINE" ]]; then | |
# execute traditional atuin_history up arrow function, interactive backwards prefix search or whatever | |
__atuin_history --shell-up-key-binding | |
return | |
fi | |
export ATUIN_ARROW_INDEX=$(( ATUIN_ARROW_INDEX + 1)) | |
export ATUIN_CYCLE_MODE=1 | |
COMMAND=$(atuin search --cmd-only --filter-mode host --limit 1 --offset $ATUIN_ARROW_INDEX) | |
LBUFFER="$COMMAND" | |
return | |
} | |
__atuin__down_arrow() { | |
export ATUIN_ARROW_INDEX=$(( ATUIN_ARROW_INDEX - 1)) | |
if [ $ATUIN_ARROW_INDEX -lt 0 ]; then | |
__atuin__reset_arrow | |
LBUFFER="" | |
return | |
fi | |
COMMAND=$(atuin search --cmd-only --filter-mode host --limit 1 --offset $ATUIN_ARROW_INDEX) | |
LBUFFER="$COMMAND" | |
return | |
} | |
__atuin__reset_arrow() { | |
export ATUIN_ARROW_INDEX=-1 | |
export ATUIN_CYCLE_MODE=0 | |
} | |
__atuin__return_key() { | |
__atuin__reset_arrow | |
zle accept-line | |
} | |
zle -N __atuin__up_arrow | |
zle -N __atuin__down_arrow | |
zle -N __atuin__return_key | |
bindkey '\eOA' __atuin__up_arrow | |
bindkey '\eOB' __atuin__down_arrow | |
bindkey '^M' __atuin__return_key |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
this is working well for me and i prefer the behavior to the
inline_height
solution because it preserves all other readline key bindings by default (eg. home/end, Ctrl+left/right, Ctrl+w,)one caveat is that if you have anything in the command buffer, it will still use the atuin TUI.
also, users may want to change their filter mode.
with this modified version of the gist, Ctrl+N can be used to cycle filter modes: