Skip to content

Instantly share code, notes, and snippets.

@Sutrannu
Created November 6, 2020 21:26
Show Gist options
  • Save Sutrannu/1173aff5cc62038eb28afbec9d618c8d to your computer and use it in GitHub Desktop.
Save Sutrannu/1173aff5cc62038eb28afbec9d618c8d to your computer and use it in GitHub Desktop.
Multiverse bashrc history
# History settings
shopt -s histappend
shopt -s cmdhist
HISTCONTROL=ignoreboth:erasedups
HISTSIZE=382500
HISTFILESIZE=382500
ONEHISTFILE=$HOME/.bash_history
multiverse(){
>$HOME/.history.tmp
history -a $HOME/.history.tmp
cat $HOME/.history.tmp | tee -a $HISTFILE $ONEHISTFILE >/dev/null
>$HOME/.history.tmp
history -c
history -r
}
cp -af $ONEHISTFILE $HOME/.history.$(basename $(tty))
export HISTFILE=$HOME/.history.$(basename $(tty))
# Prompt settings
export PROMPT_COMMAND="multiverse"

Multiverse bash history

These settings, in the .bashrc file, facilitate multiple, independent terminal sessions with a separate, unified, long-term history.

  • Each tty is given its own history file that is instantiated at logon with the combined history of all current and previous ttys
  • Each command is appended to the current fork of history as well as the unified history

The whole of the history is only available from the point where the tty forks history from the unified history file. But all history is saved for future branchings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment