Skip to content

Instantly share code, notes, and snippets.

@kevinslin
Created June 24, 2019 16:51
Show Gist options
  • Save kevinslin/376ed2f0e9ef5ad3bfcaed570eff7192 to your computer and use it in GitHub Desktop.
Save kevinslin/376ed2f0e9ef5ad3bfcaed570eff7192 to your computer and use it in GitHub Desktop.
history file
# log all history in bash with ctx
# format: {time} {cwd} {cmd}
# eg: 2018-02-03T23:12:22 /Users/kevinlin/Dropbox/code python
export PROMPT_COMMAND='if [ "$(id -u)" -ne 0 ]; then echo "$(date "+%Y-%m-%d.%H:%M:%S") $(pwd) $(history 1)" >> ~/.logs/bash-history-$(date "+%Y-%m-%d").log; fi'
# log all history in zsh with ctx
# format: {time} {cwd} {cmd}
# eg: 2018-02-03T23:12:22 /Users/kevinlin/Dropbox/code python
precmd() {
if [ "$(id -u)" -ne 0 ]; then echo $(date "+%Y-%m-%dT%H:%M:%S") $(pwd) $(fc -l -1 | awk '{for(i=2;i<=NF;++i)printf("%s ", $i)}') >> ~/.logs/zsh-history-$(date "+%Y-%m-%d").log; fi
}
export HISTSIZE=100 # lines of history to maintain memory
export SAVEHIST=1000 # lines of history to maintain in history file
export HISTFILE=~/.history
export HISTCONTROL=ignoredups
# instead of appending on shell exit
# append commands as commands are executed
setopt INC_APPEND_HISTORY
setopt EXTENDED_HISTORY # save timestamp and runtime information
setopt HIST_EXPIRE_DUPS_FIRST
setopt HIST_IGNORE_DUPS
setopt HIST_IGNORE_ALL_DUPS
setopt HIST_IGNORE_SPACE
setopt HIST_FIND_NO_DUPS
setopt HIST_SAVE_NO_DUPS
setopt HIST_BEEP
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment