| internal | ||
| scripts | ||
| go.mod | ||
| go.sum | ||
| justfile | ||
| main.go | ||
| README.md | ||
| search.sh | ||
| sync.sh | ||
verbatim
Shell history stored in SQLite, synced via git.
TODO
- More ergonomic search hook into the shell. Currently I like having
Ctrl-R as stock, and running
hswhen I need to go cross-machine or fuzzy searching.
Install
cd $HOME/dev/vlv
git clone git.meatbag.se:varl/verbatim.git verbatim
mkdir histdb
cd verbatim
go build -o verbatim .
install verbatim ~/bin
Migrate from log files
verbatim import ~/dev/vlv/histdb/
zsh
~/.zshrc:
autoload -Uz compinit promptinit add-zsh-hook
histdb_dir="$HOME/dev/vlv/histdb"
_add_history() {
if test "$(id -u)" -ne 0; then
local cmd=$(fc -ln -1)
cmd=${cmd//$'\n'/\\n}
verbatim add \
--timestamp "$(date -u +%Y-%m-%dT%H:%M:%S+00:00)" \
--hostname "$(hostname)" \
--dir "$(pwd)" \
-- "$cmd"
fi
}
add-zsh-hook precmd _add_history
# install hs (interactive search + copy to clipboard)
install scripts/hs ~/bin
Usage
verbatim [--db PATH] add --timestamp T --hostname H --dir D -- COMMAND...
verbatim [--db PATH] search [--host H] [--dir D] [--after T] [--before T] [--limit N] [QUERY...]
verbatim [--db PATH] sync [DIR]
verbatim [--db PATH] import DIR
verbatim [--db PATH] stats
Default --db: ~/.local/share/verbatim/history.db
Alternatives
Of course, there are many other shell history tools that are more mature, have more features, solve the same problem in a different way, etc:
- https://github.com/alessandrocarminati/hc
- https://github.com/ddworken/hishtory
- https://github.com/atuinsh/atuin
Those are my favourites of the ones I considered before settling on the two legacy shell scripts (later ported to Go -- and expanded on) was the fact that I want to rely on git for syncing, and I don't want to rely on a single server.
And it's hard to beat the <1ms speed of a kernel level >> for
appending a command to a file. I've accepted the trade-off of verbatim
taking ~2ms to add a record to SQLite.
With Git I can choose to pull from a specific machine, or a centralised forge depending on what I feel like, so I use that for sync.
Legacy
The old shell scripts (search.sh, sync.sh) are kept for backward
compatibility during migration. They continue to work with the log files
in the git repo.