about summary refs log tree commit diff
diff options
context:
space:
mode:
authorBarton E. Schaefer <schaefer@zsh.org>2013-10-17 07:28:52 -0700
committerBarton E. Schaefer <schaefer@zsh.org>2013-10-17 07:28:52 -0700
commitff520d1b798faa26037291e373689b5957784cc8 (patch)
tree10d802ac64e5ea5adcc58612208ed7d0b21e9314
parent73ececfd01bc137366d25940d90a34aaa2cdb02e (diff)
downloadzsh-ff520d1b798faa26037291e373689b5957784cc8.tar.gz
zsh-ff520d1b798faa26037291e373689b5957784cc8.tar.xz
zsh-ff520d1b798faa26037291e373689b5957784cc8.zip
31823: add HISTORY_IGNORE parameter
HISTORY_IGNORE defines a pattern to exclude matching lines in the internal
history from the HISTFILE at write time.
-rw-r--r--ChangeLog6
-rw-r--r--Doc/Zsh/params.yo10
-rw-r--r--Src/hist.c17
3 files changed, 33 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index 0493ab5ec..ae0e938cf 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2013-10-17  Barton E. Schaefer  <schaefer@zsh.org>
+
+	* 31836 (cf. 31823): Doc/Zsh/params.yo, Src/hist.c: add
+	HISTORY_IGNORE pattern to exclude matching lines in the
+	internal history from the HISTFILE at write time.
+
 2013-10-17  Peter Stephenson  <p.stephenson@samsung.com>
 
 	* 31830: Doc/Zsh/func.yo, README, Src/hist.c, Src/zsh.h:
diff --git a/Doc/Zsh/params.yo b/Doc/Zsh/params.yo
index 8c37c2de2..97087a1c5 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 fa5bdbb3c..1845bd8ad 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;