D&C GLug - Home Page

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

Re: [LUG] Bashrc hacks .. was lost shell history

 

On Sun, Oct 18, 2009 at 11:02:51AM +0100, John Williams wrote:
> 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.

If you use zsh, it has an option to do this automatically. setopt
SHAREHISTORY to have all running shells use the same history, and
setopt INCAPPENDHISTORY to have it update the history file every so
often, rather than just when the shell exits.

Yet another reason zsh is better than bash. ;)

-- 
Benjamin M. A’Lee || mail: bma@xxxxxxxxxxxxxx
web: http://bma.subvert.org.uk/ || gpg: 0x166891C7
“A conservative is a man who sits and thinks, mostly sits.” — Woodrow
Wilson

Attachment: pgpXfsVEywHNK.pgp
Description: PGP signature

-- 
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