Skip to content

Instantly share code, notes, and snippets.

@FiXato
Last active January 21, 2021 17:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FiXato/83a9d79af56eae0b3ac11b90e8d5fb3f to your computer and use it in GitHub Desktop.
Save FiXato/83a9d79af56eae0b3ac11b90e8d5fb3f to your computer and use it in GitHub Desktop.
Save bash history into separate files based on iTerm2 session id.
#TODO: support WSL's $WT_SESSION and tmux panes ($TMUX_PANE?)
if [ "$TERM_SESSION_ID" != "" ]; then
if [ "$HISTFILE" != "" ]; then
OLD_HISTFILE="$HISTFILE"
else
OLD_HISTFILE="~/.bash_history"
fi
HISTFILE_DIRECTORY="${HOME}/.histories/bash_histories"
mkdir -p "$HISTFILE_DIRECTORY"
HISTFILE="${HISTFILE_DIRECTORY}/bash_history-${TERM_SESSION_ID//:/-}"
if [ ! -f "$HISTFILE" ]; then
if [ -f "$OLD_HISTFILE" ]; then
cp "$OLD_HISTFILE" "$HISTFILE"
fi
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment