219 words
1 minute
Atuin for zsh shell history in SQLite
Anubhav Gain
2024-03-16

Atuin for zsh shell history in SQLite#

Atuin (via Rhet Turnbull) “replaces your existing shell history with a SQLite database”. Obviously I had to try this out!

I installed it with Homebrew:

brew install atuin

Then ran this to add it to my .zshrc config:

echo 'eval "$(atuin init zsh)"' >> ~/.zshrc

I restarted my terminal… and now I have a SQLite database full of commands I have run!

The database lives at ~/.local/share/atuin/history.db (I figured that out with this TIL), and can be opened in Datasette.

Screenshot of Datasette showing the history table from the atuin database

Removing the “up” key binding#

Atuin hijacks the Ctrl+R shortcut to provide an interactive search window, which I really like:

Screenshot of my terminal history in Atuin

But it also hijacks the Up arrow key, which I didn’t like - it interfered with how I usually use that (quickly getting back my previous command and editing it).

This thread in the Atuin issues lead me to a solution - though the fix there put my cursor at the start of the line when I wanted it at the end of the line instead. This StackExchange showed me the fix for that.

I edited my ~/.zshrc file and replaced the atuin bit at the bottom with this:

Terminal window
eval "$(atuin init zsh)"
# Restore original up binding: https://til.simonwillison.net/macos/atuin
autoload -U history-search-end
zle -N history-beginning-search-backward-end history-search-end
bindkey "^[[A" history-beginning-search-backward-end
Atuin for zsh shell history in SQLite
https://mranv.pages.dev/posts/atuin-for-zsh-shell-history-in-sqlite/
Author
Anubhav Gain
Published at
2024-03-16
License
CC BY-NC-SA 4.0