D&C GLug - Home Page

[ Date Index ] [ Thread Index ] [ <= Previous by date / thread ] [ Next by date / thread => ]

[LUG] Bashrc hacks .. was lost shell history

 

On Sat, 2009-10-17 at 21:43 +0100, Simon Waters wrote:
> Martijn Grooten wrote:
> > 
> > Did you have more than one shell window open? I have never figured out
> > how/which history is saved when you have two (or seventeen) shell
> > windows open at once and while I don't think this is the cause of the
> > problem, it might have something to do with it.
> 
> man bash, and a quick play suggests the manual page is right.
> 
> By default:
> 
> set | grep HIST
> HISTFILE=/home/srw/.bash_history
> HISTFILESIZE=500
> HISTSIZE=500
> 
> When an interactive shell exists it writes its history to the BASH
> history file with the last 500 commands in its history. The file is read
> on shell start up. So the contents of histfile depends which shell exits
> last. Always seemed a bit naff to me, I'm thinking it can't be that hard
> to use something that combines the histories of each shell sensibly.
> 

Some lines added to ~/.bashrc can do what you suggest I think, these are
what I use.

shopt -s histappend
PROMPT_COMMAND="history -n; history -a"
unset HISTFILESIZE
HISTSIZE=2000

The Prompt command is run each time you enter a command, histoy -n
reloads history, history -a updates history in the history file. It
seems back to front to me, loading it before saving, but it works, so
I'm not quibbling ;)

I have also unset the history size limit and increased the number of
lines to 2000.

The only thing to note if you jump to another terminal and want to run a
command from one you were using, is press enter once with an empty line,
that will just cause it to run the prompt commands to sync the history.


-- 
John Williams
My linux blog of notes and guides
http://subbass.blogspot.com/

Attachment: signature.asc
Description: This is a digitally signed message part

-- 
The Mailing List for the Devon & Cornwall LUG
http://mailman.dclug.org.uk/listinfo/list
FAQ: http://www.dcglug.org.uk/linux_adm/list-faq.html