atuin/src/shell/atuin.bash

41 lines
982 B
Bash
Raw Normal View History

ATUIN_SESSION=$(atuin uuid)
export ATUIN_SESSION
2021-04-26 04:50:31 -06:00
_atuin_preexec() {
local id; id=$(atuin history start -- "$1")
export ATUIN_HISTORY_ID="${id}"
2021-04-26 04:50:31 -06:00
}
_atuin_precmd() {
local EXIT="$?"
2021-04-26 04:50:31 -06:00
[[ -z "${ATUIN_HISTORY_ID}" ]] && return
2021-04-26 04:50:31 -06:00
(RUST_LOG=error atuin history end --exit "${EXIT}" -- "${ATUIN_HISTORY_ID}" &) > /dev/null 2>&1
2021-04-26 04:50:31 -06:00
}
__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
2021-04-26 04:50:31 -06:00
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
2021-04-26 04:50:31 -06:00
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