Last active
January 21, 2021 17:44
-
-
Save FiXato/83a9d79af56eae0b3ac11b90e8d5fb3f to your computer and use it in GitHub Desktop.
Save bash history into separate files based on iTerm2 session id.
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
#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