5 ms·
I store a separate bash history per directory, in a tree under ~/.bash_history.d. Each time I change directories, my shell flushes its history to that directory
by aaronharnly 15y ago
I store a separate bash history per directory, in a tree under ~/.bash_history.d. Each time I change directories, my shell flushes its history to that directory's histfile, and loads in the histfile for the new directory.
It may sound weird, but look at this way: Usually I cd to a "place" to work on some particular project. When a cd to some project I haven't touched in a while, it's very useful to have, in 'history', a context – the usual commands I use to start up that server, the last few files I fiddled with, etc.
Anyone else do something like this?
- sry_not4sale 15y agoThat is brilliant! Care to point me toward a working implementation? :)
- aaronharnly 15y agoSure -- here is the actual version from my dotfiles: https://github.com/aaronharnly/dotfiles-public/blob/master/.bash-functions.sh#L263 https://github.com/aaronharnly/dotfiles-public/blob/master/.... (You can skip the stuff wrapping virtualenv, obviously.) Basically just define a function that does the write, set HISTFILE, read, and then elsewhere alias cd=mycd. If anyone gives it a try, I'd love to hear how it works! I think it needs some tweaks -- for example, multiple terminals in the same directory are probably clobbering each other -- looks like this 'shopt -s histappend' would help with that.
- possibilistic 15y agoI am totally going to try this out! Thanks!