Skip to content

Instantly share code, notes, and snippets.

@HarrisonMc555
Last active June 19, 2018 23:05
Show Gist options
  • Save HarrisonMc555/4a0d708def7db2b9c12da739e43d8861 to your computer and use it in GitHub Desktop.
Save HarrisonMc555/4a0d708def7db2b9c12da739e43d8861 to your computer and use it in GitHub Desktop.
Save everything command entered at the terminal
mkdir -p ~/.logs
export PROMPT_COMMAND='
CODE=$?
if [ "$(id -u)" -ne 0 ]; then
COMMAND_NUMBER=$(history 1 | awk '\''{ print $1 }'\'')
COMMAND=$(history 1 | awk '\''{ s = ""; for (i = 2; i <= NF; i++) s = s $i " "; print s }'\'')
COMMAND=${COMMAND%%*( )}
printf "$(date "+%H:%M:%S")\t$(pwd)\t${COMMAND_NUMBER}\t${COMMAND}\t${CODE}\n" >> \
~/.logs/bash-history-$(date "+%Y-%m-%d").log
fi'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment