Add support for blesh (#267)

* Fix intendation

* Add support for blesh

See https://github.com/akinomyoga/ble.sh/wiki/Manual-%C2%A71-Introduction#user-content-fn-blehook for more details
This commit is contained in:
Sandro 2022-01-25 19:33:25 +01:00 committed by GitHub
parent c2dd3322c4
commit 7651f89261
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -2,34 +2,38 @@ ATUIN_SESSION=$(atuin uuid)
export ATUIN_SESSION export ATUIN_SESSION
_atuin_preexec() { _atuin_preexec() {
id=$(atuin history start "$1") id=$(atuin history start "$1")
export ATUIN_HISTORY_ID="$id" export ATUIN_HISTORY_ID="$id"
} }
_atuin_precmd() { _atuin_precmd() {
local EXIT="$?" local EXIT="$?"
[[ -z "${ATUIN_HISTORY_ID}" ]] && return [[ -z "${ATUIN_HISTORY_ID}" ]] && return
(RUST_LOG=error atuin history end "$ATUIN_HISTORY_ID" --exit $EXIT &) > /dev/null 2>&1
(RUST_LOG=error atuin history end "$ATUIN_HISTORY_ID" --exit $EXIT &) > /dev/null 2>&1
} }
__atuin_history () __atuin_history ()
{ {
tput rmkx tput rmkx
HISTORY="$(RUST_LOG=error atuin search -i "$BUFFER" 3>&1 1>&2 2>&3)" HISTORY="$(RUST_LOG=error atuin search -i "$BUFFER" 3>&1 1>&2 2>&3)"
tput smkx tput smkx
READLINE_LINE=${HISTORY} READLINE_LINE=${HISTORY}
READLINE_POINT=${#READLINE_LINE} READLINE_POINT=${#READLINE_LINE}
} }
preexec_functions+=(_atuin_preexec) if [[ -v BLE_VERSION ]]; then
precmd_functions+=(_atuin_precmd) blehook PRECMD+=_atuin_precmd
blehook PREEXEC+=_atuin_preexec
else
precmd_functions+=(_atuin_precmd)
preexec_functions+=(_atuin_preexec)
fi
if [[ -z $ATUIN_NOBIND ]]; then if [[ -z $ATUIN_NOBIND ]]; then
bind -x '"\C-r": __atuin_history' bind -x '"\C-r": __atuin_history'
fi fi