A bit of history here, a bit of history there!


This is not a post about the virtues of studying history, but, rather, a post about how to improve history management in Bash and in the Interactive Ruby Shell.


If you have multiple shells, history is rewritten by the last shell issuing a command.

To avoid the issue, put the following code in your initialization files:

# Append to history, don't overwrite it
shopt -s histappend
# Save and reload the history after each command finishes: this allows to share history across terminals
export PROMPT_COMMAND="history -a; history -c; history -r;"

Other useful customizations to history management include the following:

export HISTCONTROL=ignoredups:erasedups  # no duplicate entries
export HISTSIZE=100000                   # big big history
export HISTFILESIZE=100000               # big big history
# export HISTIGNORE='rm:rmdir:/bin/rm:cd:ls:ls -l:pwd:date:'  # ignore some dangerous and some common commands

Most of the information gotten from the Bash page on the Arch Wiki.

Interactive Ruby Shell

The interactive Ruby Shell can remember the history of commands across sessions. To remember history you need to create a .irbrc file in your home with the following code:

require 'irb/ext/save-history'
IRB.conf[:SAVE_HISTORY] = 200
IRB.conf[:HISTORY_FILE] = "#{ENV['HOME']}/.irb-history"