atuin

last updated: Sep 04, 2024

https://github.com/ellie/atuin

Atuin replaces your existing shell history with a SQLite database, and records additional context for your commands. Additionally, it provides optional and fully encrypted synchronisation of your history between machines, via an Atuin server.

I'm going to try it out, because I really want my history in a database instead of the janky history file.

Installs https://github.com/rcaloras/bash-preexec

atuin import bash imported my bash history

$ atuin stats all +---------------------+----------+ | Statistic | Value | +---------------------+----------+ | Most used command | git pull | +---------------------+----------+ | Commands ran | 8449 | +---------------------+----------+ | Unique commands ran | 5560 | +---------------------+----------+

looks about right.

Stores the db at ./.local/share/atuin/history.db, and indeed it's a simple queryable sqlite database. The config file at ~/.config/atuin/config.toml will let you change the path as well as some other stuff, but I'm just gonna leave it at the default state for now.

Would like to use litestream to back it up to s3.

Is it still echoing to ~/.bash_history? Yup:

$ tail ~/.bash_history #1650679383 git co master #1650679389 git branch -D exclude-take-3 #1650679393 git pull #1650985607 ls testing $ sqlite3 ./.local/share/atuin/history.db 'select command from history order by timestamp desc limit 5;' sqlite3 ./.local/share/atuin/history.db 'select command from history order by timestamp desc limit 5;' sqlite3 ./.local/share/atuin/history.db -c 'select command from history order by timestamp desc limit 5;' tail ~/.bash_history ls testing tail ~/.bash_history

Has search subcommand if you don't want to just query the db

this person has set up litestream replication for their atuin db, maybe I can crib from them.

replaces my fzf ctrl-r binding with something a bunch worse (fixed, see later)

Seems like you need to prepend any query with *; atuin search jq shows no results but atuin search '*jq' yields what I'd expect.

ah ha! go to ~/.config/atuin/config.toml and set search_mode to fuzzy. docs here:

## which search mode to use
## possible values: prefix, fulltext, fuzzy
search_mode = "fuzzy"

To merge history from one machine into another:

$ sqlite $(atuin info | grep -o '/.*.db') SQLite version 3.39.5 2022-10-14 20:58:05 Enter ".help" for usage hints. sqlite> attach '/path/to/remote/history.db' as remotehist; sqlite> begin; sqlite> insert into history select * from remotehist.history; sqlite> commit; sqlite> detach remotehist;

List all commands that I ran on a particular date (here, '2024-04-25'):

$ atuin history list | grep '2024-04-25' 2024-04-25 08:57:05 rg "npm run node" 543ms 2024-04-25 08:57:09 vim .github/workflows/ci.yml 6s 2024-04-25 08:57:19 gm "whoops" .github/ 152ms ...etc etc
↑ up