arch bash cakephp conf dauth devops drupal foss git golang information age life linux lua mail monitoring music mysql n900 netlog openstack perf photos php productivity python thesis travel uzbl vimeo web2.0

Per-directory bash history

I've been thinking about how a specific bash history for each directory could improve productivity, and unlike what I feared it was actually pretty easy to find a solution on the net.
Quote from an anonymous reply on

So I use the following bash function: # # Replacement for builtin 'cd', which keeps a separate bash-history # for every directory. function mycd() { history -w # write current history file builtin cd "$@" # do actual cd local HISTDIR="$HOME/.dir_bash_history$PWD" # use nested folders for history if [ ! -d "$HISTDIR" ]; then # create folder if needed mkdir -p "$HISTDIR" fi export HISTFILE="$HISTDIR/bash_history.txt" # set new history file history -c # clear memory history -r # read from current histfile } ]]>

and then set it up with the following in my bashrc:

Great stuff. It would be nice to be able to use both the global and the directory-specific history by combining with an extra modifier key .
( eg arrowup/pageup/c^r for global and alt+arrowup/alt+pageup/alt+c^r for the directory-specific one )

If I ever come up with / find something to do this I'll let you know...


thanks - this is a very useful script

do you miss having a global history or is there some way of getting all history displayed in sequential order?

Actually I never got to really using it like this. I don't like switching to non-default setups, especially if they don't work exactly the way I want.





What is the first name of the guy blogging here?

This comment form is pretty crude. Make sure mandatory fields are entered correctly.
Basic html tags (a,i,b, etc) are allowed, others are sanitized