atuin
atuin copied to clipboard
How to insert entry into history programmatically?
I have such alias:
alias nf='f=$(fd | zf); print -rs nvim $f; nvim $f'
When I run command print -rs nvim somefile
and then run history
, I see nvim somefile
is added to the history but not to atuin history.
Does #487 help? You could also take a look at the shell plugins.
So I have copied those two functions to my ~/.zshrc
and it works. Thanks.
export ATUIN_SESSION=$(atuin uuid)
ATUIN_HISTORY_ID=""
_atuin_preexec() {
local id
id=$(atuin history start -- "$1")
export ATUIN_HISTORY_ID="$id"
__atuin_preexec_time=${EPOCHREALTIME-}
}
_atuin_precmd() {
local EXIT="$?" __atuin_precmd_time=${EPOCHREALTIME-}
[[ -z "${ATUIN_HISTORY_ID:-}" ]] && return
local duration=""
if [[ -n $__atuin_preexec_time && -n $__atuin_precmd_time ]]; then
printf -v duration %.0f $(((__atuin_precmd_time - __atuin_preexec_time) * 1000000000))
fi
(ATUIN_LOG=error atuin history end --exit $EXIT ${=duration:+--duration $duration} -- $ATUIN_HISTORY_ID &) >/dev/null 2>&1
export ATUIN_HISTORY_ID=""
}
alias nf='f=$(fd | zf); print -rs nvim $f; _atuin_preexec "nvim $f"; nvim $f; _atuin_precmd $ATUIN_HISTORY_ID'