Skip to content

Instantly share code, notes, and snippets.

@wwalker
Last active January 25, 2022 23:31
Show Gist options
  • Save wwalker/f2a4ab4cc8d615a712a3737ecbbeb69a to your computer and use it in GitHub Desktop.
Save wwalker/f2a4ab4cc8d615a712a3737ecbbeb69a to your computer and use it in GitHub Desktop.
Why does this sometimes not save the session history
# ~/.bash_logout
cat "$HISTFILE" >> "$HOME"/.bash_history && /bin/rm "$HISTFILE"
SESSION_START_TIME=$(date +%F_%H.%M.%S)
mkdir -p "$HOME"/.bash_history_sessions
chmod 700 "$HOME"/.bash_history_sessions
HISTORY_SESSION_FILE=$HOME/.bash_history_sessions/$SESSION_START_TIME
HISTFILE="$HOME/.bash_history_$SESSION_START_TIME"
__save_session_history() {
[[ -n "$HISTORY_SESSION_FILE" ]] && history -a "$HISTORY_SESSION_FILE"
}
PROMPT_COMMAND='__save_session_history(); $PROMPT_COMMAND'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment