Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save pielgrzym/912281 to your computer and use it in GitHub Desktop.
Save pielgrzym/912281 to your computer and use it in GitHub Desktop.
Zsh history tweaking
freeze_hist() {
fc -p # pop current history into stack
HISTFILE=`pwd`/.zsh_custom_history
SAVEHIST=10000
HISTSIZE=10000
}
unfreeze_hist() {
fc -p `pwd`/.zsh_custom_history
HISTFILE=`pwd`/.zsh_custom_history
SAVEHIST=10000
HISTSIZE=10000
}
HBD="/home/pielgrzym/var/hist_test"
HBD_LOCK=0
chpwd() {
if [[ $PWD = $HBD* && $HBD_LOCK -eq 0 ]]
then
HBD_LOCK=1
echo "Setting the lock"
if [[ -s .zsh_custom_history && -r .zsh_custom_history && -w .zsh_custom_history ]]
then
echo "Unfreezing history!"
unfreeze_hist
fi
fi
if [[ $PWD != $HBD* && $HBD_LOCK -ne 0 ]]
then
HBD_LOCK=0
echo "Resetting the lock"
fc -P
echo "Restoring global history"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment