atuin icon indicating copy to clipboard operation
atuin copied to clipboard

How to insert entry into history programmatically?

Open rofrol opened this issue 1 year ago • 1 comments

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.

rofrol avatar May 10 '23 10:05 rofrol

Does #487 help? You could also take a look at the shell plugins.

YummyOreo avatar May 11 '23 20:05 YummyOreo

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'

rofrol avatar Jan 10 '24 07:01 rofrol