From: Peter Stephenson <pws@csr.com>
To: zsh-workers@sunsite.dk (Zsh hackers list)
Subject: Re: Local history
Date: Mon, 19 Nov 2001 17:36:32 +0000 [thread overview]
Message-ID: <16721.1006191392@csr.com> (raw)
In-Reply-To: "Bart Schaefer"'s message of "Mon, 19 Nov 2001 16:48:24 GMT." <1011119164824.ZM27974@candle.brasslantern.com>
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 <pws@csr.com> 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.
**********************************************************************
next prev parent reply other threads:[~2001-11-19 17:37 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-11-16 17:27 Peter Stephenson
2001-11-16 17:54 ` Oliver Kiddle
2001-11-16 18:01 ` Danek Duvall
2001-11-19 8:40 ` Wischnowsky, Sven
2001-11-19 16:48 ` Bart Schaefer
2001-11-19 17:36 ` Peter Stephenson [this message]
2001-11-19 17:58 ` Bart Schaefer
2001-11-21 18:57 ` history editing Danek Duvall
2001-11-21 22:21 ` Wayne Davison
2001-11-21 22:30 ` Danek Duvall
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=16721.1006191392@csr.com \
--to=pws@csr.com \
--cc=zsh-workers@sunsite.dk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).