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.
::Read from here
Quote from an anonymous reply on debian-administration.org
#
# Usage: mycd <path>
#
# 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:
shopt -s histappend
alias cd="mycd"
export HISTFILE="$HOME/.dir_bash_history$PWD/bash_history.txt"
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...
posted on Wednesday, 30 Jan 2008 21:37 - link - tags: bash, productivity - path: / - 2 comments
Posted by Jeremy Leipzig on Thu Jun 25 17:49:26 2009
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.
Posted by Dieter_be on Sun Jun 28 09:13:52 2009
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?