“infinite” bash history

I tend to use `screen`a lot and never reboot my computers. As my memory becomes flaky, I often need to search in my history and usually don’t remember which tab I used for a specific command.

I’ve solved this problem with my bashrc the following way:

# don't put duplicate lines or lines starting with space in the history.
# See bash(1) for more options
export HISTCONTROL=ignoredups:erasedups

# append to the history file, don't overwrite it
shopt -s histappend

# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
export HISTSIZE=100000
export HISTFILESIZE=200000

function history_sync {
 history -a
 history -c
 history -r

function hist {
 history -a
 history -c
 history -r
 builtin history

alias hgrep="hist|grep"

I can now use hist to “update history and display”  and hgrep to grep on history. Synchronization is still opt-in but it’s good enough.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s