Last active
January 3, 2016 11:49
-
-
Save iamralpht/8458868 to your computer and use it in GitHub Desktop.
bashrc hacks for per-directory history
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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