Skip to content

Instantly share code, notes, and snippets.

@cdornsife
Created February 20, 2017 17:49
Show Gist options
  • Select an option

  • Save cdornsife/096141d3d89d4b8fe10650a2966af951 to your computer and use it in GitHub Desktop.

Select an option

Save cdornsife/096141d3d89d4b8fe10650a2966af951 to your computer and use it in GitHub Desktop.
Zsh forever history
#set history size
export HISTSIZE=5000
#save history after logout
export SAVEHIST=5000
#history file
export HISTFILE=~/.zhistory
#append into history file
setopt INC_APPEND_HISTORY
#save only one command if 2 common are same and consistent
setopt HIST_IGNORE_DUPS
#add timestamp for each entry
setopt EXTENDED_HISTORY
# Store the last command in a dated history file
precmd(){
if [ "$(id -u)" -ne 0 ];
then
echo "$(date "+%Y-%m-%d.%H:%M:%S") $(pwd) $(history | awk 'END{$1=""; print $0}')" >> ~/.logs/bash-history-$(date "+%Y-%m-%d").log;
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment