zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: "Zsh Hackers' List" <zsh-workers@zsh.org>
Subject: Re: Finer control over what gets written to the history file
Date: Thu, 17 Oct 2013 07:20:22 -0700	[thread overview]
Message-ID: <131017072022.ZM5433@torch.brasslantern.com> (raw)
In-Reply-To: <20131016102008.69640804@pwslap01u.europe.root.pri>

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) <S>)(
 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;
 


  reply	other threads:[~2013-10-17 14:20 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-15 16:41 Bart Schaefer
2013-10-15 16:58 ` Peter Stephenson
2013-10-16  0:34   ` Bart Schaefer
2013-10-16  8:55     ` Peter Stephenson
2013-10-16  9:20       ` Peter Stephenson
2013-10-17 14:20         ` Bart Schaefer [this message]
2013-10-17 14:28           ` Peter Stephenson
2013-10-16 10:04       ` Peter Stephenson
2013-10-16  5:25   ` Bart Schaefer
2013-10-16  8:35     ` Peter Stephenson

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=131017072022.ZM5433@torch.brasslantern.com \
    --to=schaefer@brasslantern.com \
    --cc=zsh-workers@zsh.org \
    /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).