Saving history with vcsh

I’ve written a few articles on using vcsh for tracking your home dir. Unlike previous options vcsh lets me use multiple repositories. My first experiment with this was a past repository.

Lots of Unix tools use the GNU readline library so there are a number of history files to collect. I already was collecting all of them in ~/.history.d. In addition due to problems with NFS mounted home dirs I’d long ago put the hostname in the names of history files as a way to prevent file corruption.

That means it’s collection of files that won’t need merging but might be nice to have. I used to connect to machines just to look in history files to remember how I’d done a thing. With a ~/bin and a vcsh tracked home dir it was less common as I often turn complicated things into scripts, but I still have the odd long pipeline that doesn’t really lend itself to being a script but I might need it a few times.

The past repo now tracks all changes to ~/.history.d and generally w/o me having to do anything. My ~/.zlogout file contains this:

if [[ -d ~/.history.d ]]; then
  vcsh past add ~/.history.d > /dev/null 2>&1
  if [[ $(vcsh past diff-index -p HEAD | wc -l) -gt 30 ]]; then
    # Commit once at least 20 commands have been added (extra lines for
    # git and diff headers).
    vcsh past ci -m \
      "[${HOST%%.*}] .zlogout auto commit for ~/.history.d." ~/.history.d

This will make sure to add any new histories and add when already tracked histories grow. I also set the past repo to do rebases by default. There’s no real chance for complicated merges so it saves a lot of merge commits.

This provides data for loads of really useful commands. The most obvious is vcsh past grep 'command.*an-arg' ~ to look for history. But the files are only so big, right? History files get truncated. Except these ones don’t - vcsh past log -S'command.*an-arg' will find me the commits where that command last was. And both have been useful in the past:

: ok;: Tue 15 9:01; cd ~/src/;: {master}
: kevin@sunset on ttys009; vcsh past grep 'vcsh past grep' ~|wc -l
: ok;: Tue 15 9:01; cd ~/src/;: {master}
: kevin@sunset on ttys009; vcsh past grep 'vcsh past log' ~|wc -l

So far not useful enough that I’ve wrapped them in scripts, but certainly things that have helped me a lot over the past several years.

In a way it’s another step to making my home dir like a Smalltalk workspace. I can save little snippets of useful commands in past, more fleshed out scripts in home - as well as configurations and a way to add in additional tools. As I learn new tools I store those steps away so I can revisit/relearn them.