Skip to content

Instantly share code, notes, and snippets.

@therevoman
Created September 19, 2022 18:50
Show Gist options
  • Save therevoman/a7532af575479f0a2b5edfbb0bef8212 to your computer and use it in GitHub Desktop.
Save therevoman/a7532af575479f0a2b5edfbb0bef8212 to your computer and use it in GitHub Desktop.
deduped_bash_history
HISTCONTROL=ignorespace:ignoredups:erasedups
shopt -s histappend
HISTSIZE=-1
HISTFILESIZE=-1
#HISTTIMEFORMAT="[%Y%m%d %H%M%S] "
HISTTIMEFORMAT="[%b %d,%Y %T] "
PROMPT_COMMAND="history -a;${PROMPT_COMMAND}"
function deduphistory {
echo "deduphistory"
history -w ~/.bash_history.dedup_backup
history -n; history -a
#history | sort --key=5 | uniq --skip-fields=4 | sort --key=1
tac ~/.bash_history | awk '!x[$0]++' | tac > ~/.bash_history_new_dedup
history -cr ~/.bash_history_new_dedup
history -w
}
# cleanup bash history on exit
trap deduphistory EXIT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment