sqlite-backed shell history

zsh integration script #1

Closed oppi.li
Closed opened by oppi.li

Hallo hallo!

First and foremost, thank you very much for this tool, it's been a lovely addition to my setup 😃

I had to come up with the below script for stinkpot to work under zsh, which I thought might be useful to others. I'm happy to contribute it myself via a PR á la the fish shell integration one.

if command -v stinkpot >/dev/null 2>&1; then
    # Record every command + exit code before each prompt
    __stinkpot_record() {
        local exit=$?
        local cmd
        cmd=$(fc -ln -1 2>/dev/null)
        [ -n "$cmd" ] && stinkpot add --exit "$exit" -- "$cmd"
    }
    precmd_functions+=(__stinkpot_record)

    # Ctrl+R → stinkpot search
    __stinkpot_search() {
        local out
        out=$(stinkpot search -- "$BUFFER" </dev/tty) || return
        if [ -n "$out" ]; then
            BUFFER="$out"
            CURSOR=${#BUFFER}
            zle redisplay
        fi
    }
    zle -N __stinkpot_search
    bindkey '^R' __stinkpot_search
fi

Cheers, Gorka.

feel free to open this as a PR!

this is now completed (by you!)

Sign up or Sign in to add to the discussion.