Po Lu <luangruo@yahoo.com> writes:
> anyone who has run multiple bash shells in parallel,
> and thus played the guessing game of "which shell's history has been
> preserved?" will concur.
I definitely find the bash history experience extremely annoying. It
happens even when bash is exited cleanly - it's just a consequence of
the fact that bash overwrites the previous history when exiting, rather
than combining them in some way.
Just as a complete aside for preventing bash history erasure, I got around it like this:
* shopt -s histappend # append to the history file, don't overwrite it
* HISTIGNORE='cd "`printf "%b"*' # Need this so tab filename completion lines don't get stored
* export HISTCONTROL=ignoreboth # I could also have used erasedups here but felt this would be unacceptably slow
* export HISTSIZE=30000000 # Yes, it's huge, but I get history going back years
I prevent history erasure by the simple process of defining history to be huge (30Mb) and save each line as I hit enter without trimming the .bash_history shorter. The one disadvantage I've struck so far is that I have very long bash startup times. I get around that to a degree by periodically trimming history down to a more sane 10,000 lines after archiving to a master file. I also load 1k lines of history each time I start up a shell, hence the longer startup times.
Relating to history searches, I tend to use grep "my pattern" ~/.bash_history first, and if I don't find what I want there (a really unusual occurrence now) I grep the master file as well. I have history going back several years, and that has saved my time more times than I can remember.
I hope that's a useful diversion from the intricacies of emacs history saving, and might give a tip or two to those bash users among us.
Regards, brickviking