atuin/src/shell/atuin.bash
Patrick Decat ed394afa82
Allow overriding filter and search modes from CLI (#635)
* Allow overriding filter and search modes from CLI arguments

* Use session filter mode for bash up key binding

* We precisely do not want to add quotes here so that all arguments are properly passed

* Add --shell-up-key-binding hidden command argument and filter_mode_shell_up_key_binding configuration option to allow customizing the filter mode used when atuin is invoked from a shell up-key binding

* Correct up binding for zsh

Co-authored-by: Ellie Huxtable <ellie@elliehuxtable.com>
2022-12-18 18:26:09 +00:00

40 lines
982 B
Bash

ATUIN_SESSION=$(atuin uuid)
export ATUIN_SESSION
_atuin_preexec() {
local id; id=$(atuin history start -- "$1")
export ATUIN_HISTORY_ID="${id}"
}
_atuin_precmd() {
local EXIT="$?"
[[ -z "${ATUIN_HISTORY_ID}" ]] && return
(RUST_LOG=error atuin history end --exit "${EXIT}" -- "${ATUIN_HISTORY_ID}" &) > /dev/null 2>&1
}
__atuin_history ()
{
tput rmkx
# shellcheck disable=SC2048,SC2086
HISTORY="$(RUST_LOG=error atuin search $* -i -- "${READLINE_LINE}" 3>&1 1>&2 2>&3)"
tput smkx
READLINE_LINE=${HISTORY}
READLINE_POINT=${#READLINE_LINE}
}
if [[ -n "${BLE_VERSION-}" ]]; then
blehook PRECMD-+=_atuin_precmd
blehook PREEXEC-+=_atuin_preexec
else
precmd_functions+=(_atuin_precmd)
preexec_functions+=(_atuin_preexec)
fi
if [[ -z ${ATUIN_NOBIND} ]]; then
bind -x '"\C-r": __atuin_history'
bind -x '"\e[A": __atuin_history --shell-up-key-binding'
bind -x '"\eOA": __atuin_history --shell-up-key-binding'
fi