9 Comments
Jan 21Liked by Thorsten Ball

The oldest entry in my history.sql is dated Wed Oct 17 13:07:38 CEST 2012. It's a bit of a hack, using PROMPT_COMMAND to push entries into this table:

CREATE TABLE history (pid INTEGER, host TEXT, date INTEGER, cwd TEXT, starttime INTEGER, command TEXT);

It's pretty much a gross hack that started with "history 1" and grew to include this and that, needed some formatting, needed a tmpfile (though probably not, really) and then squeeze it into the db.

export PROMPT_COMMAND='printf "%s^A%s^A%s^A%s^A%s\n" "$$" "$(hostname)" "$(date +%s)" "$(pwd)" "$(HISTTIMEFORMAT="%s^A" history 1 | sed "s/^ *[^ ]* *//g")" > /tmp/hinser;sqlite3 -separator ^A ~/someplace/bash_history.sql ".import /tmp/hinser history"'

The ^As are literal 001 to act as separators, I tried a number of other ways of separating the fields, ended up with ^A since that character seldom shows up in cmdlines or in any of the other fields.

Currently there are 198K lines of history, dumped to text it amounts to about 20MBs of text.

Expand full comment
author

Love it!

Expand full comment

Love atuin ! One of the better shell feature replacements i have come to appreciate this past year

Expand full comment

Love it, thanks a lot!

Expand full comment

how did you set up `ctrl+r` to execute `fzf` on your zsh history? i couldn't find anything in our dotfiles repo :)

Expand full comment
author

It's in the standard fzf shell setup, see: https://github.com/junegunn/fzf#key-bindings-for-command-line

But also: I'm trying out Atuin right now, so I might have removed it, not sure

Expand full comment

I found it there but was missing it from your repo - you might have removed it. Thanks!

I am kind of hesitant to up the complexity from a single text file to a database which is synchronised via network.

At the same time I was wondering how you have kept your zsh histories in sync on multiple machines - did you use git?

Expand full comment
author

I just copied (or forgot) the files over from machine to machine and then they'd diverge, yeah. No system.

So now I'm trying atuin (which still means shell writes to history files!)

Expand full comment

ctrl r definitely feels like a super power, it's super cool

Expand full comment