Jay Taylor's notes

back to listing index

Historian: Because Please, Stop Deleting My Bash History

[web search]
Original source (undertitled.com)
Tags: bash history command-line backups sqlite undertitled.com
Clipped on: 2017-04-12

Historian: Because Please, Stop Deleting My Bash History

Apr 12, 2017

.bash_history is like having your own stenographer at your side whenever you’re in a console. “Let’s go to the transcript,” you can say with Ctrl-r, which triggers reverse-search-history.

“What was my last figlet?”

“It was figlet moo | cowsay.”

“How’d that turn out?”

“Not… great.”

 _________________________________________
/                                         \
|                                         |
| _ __ ___ ___ ___ | '_ ` _ \ / _ \ / _ \ |
| | | | | | | (_) | (_) | |_| |_|         |
\ |_|\___/ \___/                          /
 -----------------------------------------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||
* * *

The last few versions of MacOS have introduced random fires which burn down your .bash_history, leaving this occasional sad, sad result:

$ wc -l .bash_history
0

Of course, since you’ve got a good backup & restore strategy, you can pluck out the last version of .bash_history and no one is the wiser.

Right? Yes, of course. Absolutely.

* * *

For the rest of us, the unwashed masses, enter historian.

In its nascent form, a script backs up your .bash_history into a SQLite database that sits in your home directory as well.

To get started:

$ hist import
Imported 6893 item(s).

What have you done with git?

$ hist search git
815
        git clone https://github.com/garybernhardt/selecta.git
768
        git push -u origin master
767
        git remote add origin git@github.com:jcsalterego/historian.git
711
        git init ; git add  . ; git commit -am "Initial commit."

Maybe you like less typing? Use the / shorthand for search:

$ hist /commit
883
        git commit -am 'Quick clarification'
882
        git commit -am "Super Installation notes"
275
        git commit -am ":clowndance:"
229
        git commit -am ":carol:"

And finally, since nobody has time to manually run hist import, attach it to the end of your .profile and voilà — instant imports when you start a new shell.  ū