Skip to content

Instantly share code, notes, and snippets.

@elchead
Created December 5, 2022 09:26
Show Gist options
  • Save elchead/f3135f872ff3dc66ee3e9681aaea2c9a to your computer and use it in GitHub Desktop.
Save elchead/f3135f872ff3dc66ee3e9681aaea2c9a to your computer and use it in GitHub Desktop.
Consistent bash history across sessions
export HISTCONTROL=ignoredups:erasedups # no duplicate entries
export HISTSIZE=100000 # big big history
export HISTFILESIZE=100000 # big big history
# shopt -s histappend # append to history, don't overwrite it
# Save and reload the history after each command finishes
#export PROMPT_COMMAND="history -a; history -c; history -r; $PROMPT_COMMAND"
HISTCONTROL=ignorespace:ignoredups
_bash_history_sync() {
builtin history -a #1
HISTFILESIZE=$HISTSIZE #2
builtin history -c #3
builtin history -r #4
}
history() { #5
_bash_history_sync
builtin history "$@"
}
PROMPT_COMMAND=_bash_history_sync
# Source https://unix.stackexchange.com/a/48116
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment