Tuesday, January 24

shell history using RASH

Back in October of 2016, I mentioned that I’d started working on a utility called commandlog for keeping Bash and Zsh shell history in a database. My proof-of-concept was tiny and didn’t do much, but it seemed like an obviously fruitful idea. Especially after I talked to friends about the idea of using shell history to build up a kind of logbook and per-directory menu system

I’m fighting a cold tonight and too fuzzy in the head to work on anything very complicated, so I thought I’d hack on commandlog a bit. It occurred to me that I hadn’t really looked very hard at other alternatives, so I did some googling first.

Sure enough, people have done some work. I’m tagging a few things under “shell-history” on Pinboard. The most promising thing I’ve found so far is a Python project called RASH. Like commandlog, it keeps history in an SQLite db, albeit with a weird intermediate step where JSON files are written to a directory and then added to the database by a daemon process.

RASH seems to have a bunch of the features I want out of a tool like this. For example, you can search history by the current directory:

$ rash search -d .
v index
touch tag-technical tag-commandlog

Or use a regexp to look for commands beginning with comment, and display 5 lines of context on either side of them:

$ rash search -M '^comment' -C 5
rash search -M comment -C 3 --with-command-id
rash search -M comment -C 3
rash search -M comment
rash search -h
rash search
comment "checking out rash for shell history logging"
sqlite3 ./db.sqlite
rash search -h

…which is useful because I use comment "foo" to toss in little descriptions of tasks. It also logs a customizable set of environment variables, which would probably be the right thing if I wanted to add tagging or grouping of commands.

My hesitation is that it’s a Python project with a low version number and only partial Python 3 support, and development appears to have stopped some time in 2015. Still, it’s promising. I probably shouldn’t write my own version of all this if an existing project proves to work.