Last active
October 18, 2019 00:14
-
-
Save wwalker/c0ecd0b22db4f61ee290891d848b82ff to your computer and use it in GitHub Desktop.
How to get bash per session history files, which is updated with each command in real time, and, upon session exit, appends the entire session history to ~/.bash_history
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Take the session history and append it to the .bash_history file, and if successful, remove the session file | |
cat "$HISTFILE" >> "$HOME"/.bash_history && /bin/rm "$HISTFILE" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Store the time the session started | |
SESSION_START_TIME=$(date +%F_%H.%M.%S) | |
HISTCONTROL= | |
HISTSIZE=100000 | |
HISTFILESIZE=100000 | |
HISTTIMEFORMAT='%F %T - ' | |
shopt -s histappend | |
shopt -s histreedit | |
shopt -s histverify | |
shopt -s cmdhist | |
HISTFILE="$HOME/.bash_history_$SESSION_START_TIME" | |
PROMPT_COMMAND="history -a;$PROMPT_COMMAND" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment