Skip to content

Instantly share code, notes, and snippets.

@casssoft
Created May 2, 2019 17:13
Show Gist options
  • Save casssoft/d397514ca3a10c3fd938b1019d88c0d4 to your computer and use it in GitHub Desktop.
Save casssoft/d397514ca3a10c3fd938b1019d88c0d4 to your computer and use it in GitHub Desktop.
bash session history
# this needs to be at the end of bash setup (possibly at the end of ~/.bashrc)
# use script because it works and is installed by default
# this also requires the user to double exit out
# NOTE: trying to replicate it with bash -il 2>$1 | tee .terminal_session fails with an infinite loop
if [ "$IN_SCRIPT_SESSION" != "0" ]; then
mkdir -p ~/.bash_session_history/
# this might get really big so report it everytime
echo "bash session history size: $(du -h ~/.bash_session_history)"
export IN_SCRIPT_SESSION=0
# use script -q -e if you want to not see the script messages
script -e ~/.bash_session_history/$(date +2%3y_%2m_%2d_%s%3N)
else
# tell people its being recording
export PS1="${PS1}rec$ "
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment