Skip to content

Instantly share code, notes, and snippets.

@iamralpht
Last active January 3, 2016 11:49
Show Gist options
  • Save iamralpht/8458868 to your computer and use it in GitHub Desktop.
Save iamralpht/8458868 to your computer and use it in GitHub Desktop.
bashrc hacks for per-directory history
# Hack to implement per-directory history. If you run the same commands in the same directories,
# then why not have a separate history for each directory?
HISTBASE=~/.bash_directory_hist
LASTHIST=
_hash() {
echo "$@" | sha512sum | cut -f1 -d' '
}
_load_history() {
LASTHIST="$HISTBASE/$(_hash $(pwd))"
HISTFILE=$LASTHIST
history -c
history -r
}
prompt_cd() {
NEXTHISTFILE="$HISTBASE/$(_hash $(pwd))"
#if [ "$LASTHIST" -ne "$NEXTHISTFILE" ]
#then
history -w
_load_history
#fi
}
PROMPT_COMMAND=prompt_cd
mkdir -p "$HISTBASE"
_load_history
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment