Worth while bash hack (makes history even more valuable)

David Mandala plug-discuss@lists.plug.phoenix.az.us
11 Mar 2003 08:39:58 -0700


Tip for those of you who use bash as their primary shell.

I came across this a couple of months ago and tried it. Really makes
bash history much more worth it. Keeps out standard items that I don't
need and keep around longer stuff that I do want.

In .bash_profile add:

HISTIGNORE="&:ls:ls *:ps axww:cd ..:killev:mutt:[bf]g:exit"
export HISTIGNORE

In .bashrc add:

shopt -s histappend

Also to help keep me from doing really stupid things without thinking
first. Won't stop me from doing something stupid, but at least I have to
think about it a moment more and sometimes that helps. 

Also add to .bashrc:

# User specific aliases and functions
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'

and finally to .bash_logout add:

nl ~/.bash_history | sort -uk2 | sort | colrm 1 8 >~/.bash_hist_min
rm ~/.bash_history
mv ~/.bash_hist_min ~/.bash_history

Then re-source .bash_profile by:

. ./.bash_profile in your open terminals and over time watch your
history leave out useless stuff and keep handy things around longer.

For those that are interested the HISTIGNORE command tells bash not to
add the same command twice in a row to the history, don't add ls
"anything" or ps axww or cd .. or killev or mutt or bg or fg or exit to
the history queue. Handy. I add stuff here once in a while when I see
commands stack up in my history file that I don't need nor want. 

I had forgotten how useful this was until I upgraded a machine and
forgot to save these settings. Shortly I was getting frustrated with
bash and had a hell of a time remembering what I had done to make it
nicer.

Cheers,

Davidm
-- 
David IS Mandala
gpg fingerprint 8932 E7EF CCF5 1B8C 1B5C A92E C678 795E 45B2 D952
Phoenix, AZ (480) 460-7545 HP, (602) 741-1363 CP
http://www.them.com/~davidm/