about summary refs log tree commit diff
path: root/Src/hist.c
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 /Src/hist.c
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.
Diffstat (limited to 'Src/hist.c')
-rw-r--r--Src/hist.c17
1 files changed, 17 insertions, 0 deletions
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;