Skip to content

Instantly share code, notes, and snippets.

@AlLongley
Forked from thomaslaurenson/better_history.sh
Last active March 10, 2020 23:37
Show Gist options
  • Save AlLongley/db28447ba336bcb54fa0b9d981da9b67 to your computer and use it in GitHub Desktop.
Save AlLongley/db28447ba336bcb54fa0b9d981da9b67 to your computer and use it in GitHub Desktop.
# Custom history configuration
# Run script using:
# chmod u+x better_history.sh
# sudo su
# ./better_history.sh
GLOBALRC = /etc/bashrc
echo ">>> Starting"
echo ">>> Loading configuration into $GLOBALRC"
echo "HISTTIMEFORMAT='%F %T '" >> $GLOBALRC
echo 'HISTFILESIZE=-1' >> $GLOBALRC
echo 'HISTSIZE=-1' >> $GLOBALRC
echo 'HISTCONTROL=ignoredups' >> $GLOBALRC
echo 'HISTIGNORE=?:??' >> $GLOBALRC
echo '# append to history, dont overwrite it' >> $GLOBALRC
echo 'shopt -s histappend' >> $GLOBALRC
echo '# attempt to save all lines of a multiple-line command in the same history entry' >> $GLOBALRC
echo 'shopt -s cmdhist' >> $GLOBALRC
echo '# save multi-line commands to the history with embedded newlines' >> $GLOBALRC
echo 'shopt -s lithist' >> $GLOBALRC
echo '# After each command, append to the history file and reread it' >> $GLOBALRC
echo 'export PROMPT_COMMAND="${PROMPT_COMMAND:+$PROMPT_COMMAND$"\n"}history -a; history -c; history -r"' >> $GLOBALRC
# Reload BASH for settings to take effect
echo ">>> Reloading BASH"
exec "$BASH"
echo ">>> Finished. Exiting."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment