From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24388 invoked by alias); 17 Oct 2013 14:20:43 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 31836 Received: (qmail 11601 invoked from network); 17 Oct 2013 14:20:36 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 From: Bart Schaefer Message-id: <131017072022.ZM5433@torch.brasslantern.com> Date: Thu, 17 Oct 2013 07:20:22 -0700 In-reply-to: <20131016102008.69640804@pwslap01u.europe.root.pri> Comments: In reply to Peter Stephenson "Re: Finer control over what gets written to the history file" (Oct 16, 10:20am) References: <131015094100.ZM2399@torch.brasslantern.com> <20131015175838.19f0256d@pwslap01u.europe.root.pri> <131015173453.ZM2606@torch.brasslantern.com> <20131016095524.1340a535@pwslap01u.europe.root.pri> <20131016102008.69640804@pwslap01u.europe.root.pri> X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: "Zsh Hackers' List" Subject: Re: Finer control over what gets written to the history file MIME-version: 1.0 Content-type: text/plain; charset=us-ascii On Oct 16, 10:20am, Peter Stephenson wrote: } } Oh, wait, you're saying you didn't even realise at the time you wanted } to omit the lines. You want something you can activate at the point } you're about to run fc -W or exit the shell. So that would have to be } a different hook, which isn't really appropriate for running on every } line of a potentially huge file. So probably your way is as good as it } gets. OK, here's a final patch including doc. Nobody commented on the memory management question and a push/pop heap is harmless if the heap is never used, so ... Hmm, this fails silently if the pattern can't be compiled. I'll leave any warnings to the next patch. diff --git a/Doc/Zsh/params.yo b/Doc/Zsh/params.yo index 8c37c2d..97087a1 100644 --- a/Doc/Zsh/params.yo +++ b/Doc/Zsh/params.yo @@ -967,6 +967,16 @@ item(tt(HISTFILE))( The file to save the history in when an interactive shell exits. If unset, the history is not saved. ) +vindex(HISTORY_IGNORE) +item(tt(HISTORY_IGNORE))( +If set, is treated as a pattern at the time history files are written. +Any potential history entry that matches the pattern is skipped. For +example, if the value is `tt(fc *)' then commands that invoke the +interactive history editor are never written to the history file (compare +the tt(HIST_NO_STORE) option or the tt(zshaddhistory) hook, either of +which would prevent such commands from being added to the interactive +history at all). +) vindex(HISTSIZE) item(tt(HISTSIZE) )( The maximum number of events stored in the internal history list. diff --git a/Src/hist.c b/Src/hist.c index fa5bdbb..1845bd8 100644 --- a/Src/hist.c +++ b/Src/hist.c @@ -2600,12 +2600,27 @@ savehistfile(char *fn, int err, int writeflags) } } if (out) { + char *history_ignore; + Patprog histpat = NULL; + + pushheap(); + + if ((history_ignore = getsparam("HISTORY_IGNORE")) != NULL) { + tokenize(history_ignore = dupstring(history_ignore)); + remnulargs(history_ignore); + histpat = patcompile(history_ignore, 0, NULL); + } + ret = 0; for (; he && he->histnum <= xcurhist; he = down_histent(he)) { if ((writeflags & HFILE_SKIPDUPS && he->node.flags & HIST_DUP) || (writeflags & HFILE_SKIPFOREIGN && he->node.flags & HIST_FOREIGN) || he->node.flags & HIST_TMPSTORE) continue; + if (histpat && + pattry(histpat, metafy(he->node.nam, -1, META_HEAPDUP))) { + continue; + } if (writeflags & HFILE_SKIPOLD) { if (he->node.flags & (HIST_OLD|HIST_NOWRITE)) continue; @@ -2685,6 +2700,8 @@ savehistfile(char *fn, int err, int writeflags) histactive = remember_histactive; } } + + popheap(); } else ret = -1;