From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 21811 invoked from network); 19 Nov 2001 17:37:11 -0000 Received: from sunsite.dk (130.225.247.90) by ns1.primenet.com.au with SMTP; 19 Nov 2001 17:37:11 -0000 Received: (qmail 12404 invoked by alias); 19 Nov 2001 17:37:03 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 16267 Received: (qmail 12373 invoked from network); 19 Nov 2001 17:37:02 -0000 To: zsh-workers@sunsite.dk (Zsh hackers list) Subject: Re: Local history In-reply-to: "Bart Schaefer"'s message of "Mon, 19 Nov 2001 16:48:24 GMT." <1011119164824.ZM27974@candle.brasslantern.com> Date: Mon, 19 Nov 2001 17:36:32 +0000 Message-ID: <16721.1006191392@csr.com> From: Peter Stephenson Bart Schaefer wrote: > As Sven mentioned, I've done this before. The basic trick is that HISTSIZE > truncates the history as soon as you assign to it, so the technique goes > like this: > > local temphist=${TMPPREFIX}hist SAVEHIST=$HISTSIZE > HISTFILE=$temphist > fc -W # Save internal history > local HISTSIZE=0 # Truncate internal history > HISTSIZE=$SAVEHIST > HISTFILE=~/.zcalc-history > fc -R # Read previous zcalc history > # do zcalc stuff ... > fc -W # Save zcalc history > HISTFILE=$temphist > fc -R # Reload old history That should obviously restore the original HISTFILE at the second last line. I adapted this into the following, and it's mostly working fine. However, every time it saves back to ~/.zcalc_history, it adds two lines from the old history at the start which I can't seem to get rid of. Possibly trimming SAVEHIST to the actual number of lines to save might work. Index: Functions/Misc/zcalc =================================================================== RCS file: /cvsroot/zsh/zsh/Functions/Misc/zcalc,v retrieving revision 1.5 diff -u -r1.5 zcalc --- Functions/Misc/zcalc 2001/11/15 18:42:33 1.5 +++ Functions/Misc/zcalc 2001/11/19 17:27:44 @@ -88,6 +88,25 @@ emulate -L zsh setopt extendedglob +# can't be local since required in EXIT trap +zcalc_orighist=$HISTFILE +local temphist=${TMPPREFIX}hist SAVEHIST=$HISTSIZE +HISTFILE=$temphist +fc -W + +local HISTSIZE=0 +HISTSIZE=$SAVEHIST +HISTFILE=~/.zcalc_history +[[ -f $HISTFILE ]] && fc -R + +zcalc_restore() { + unfunction zcalc_restore + fc -W + HISTFILE=$zcalc_orighist + fc -R +} +trap zcalc_restore HUP INT QUIT EXIT + local line latest base defbase match mbegin mend psvar optlist opt arg integer num -- Peter Stephenson Software Engineer CSR Ltd., Science Park, Milton Road, Cambridge, CB4 0WH, UK Tel: +44 (0)1223 392070 ********************************************************************** The information transmitted is intended only for the person or entity to which it is addressed and may contain confidential and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from any computer. **********************************************************************