summaryrefslogtreecommitdiff
path: root/Src/hist.c
diff options
context:
space:
mode:
authorPeter Stephenson <pws@zsh.org>2013-10-17 10:14:25 +0100
committerPeter Stephenson <pws@zsh.org>2013-10-17 10:14:25 +0100
commit73ececfd01bc137366d25940d90a34aaa2cdb02e (patch)
treedb9a9969a06a81fe1efafa38829e6e1a44f5eddc /Src/hist.c
parenta8f736b4cf8d186af4aea6f48ae7a5335d9ad8bb (diff)
downloadzsh-73ececfd01bc137366d25940d90a34aaa2cdb02e.tar.gz
zsh-73ececfd01bc137366d25940d90a34aaa2cdb02e.zip
31830: New feature for zshaddhistory hooks.
If the first non-zero return status is 2, save the line on the internal history list, but don't write it out.
Diffstat (limited to 'Src/hist.c')
-rw-r--r--Src/hist.c25
1 files changed, 21 insertions, 4 deletions
diff --git a/Src/hist.c b/Src/hist.c
index ed9560952..fa5bdbb3c 100644
--- a/Src/hist.c
+++ b/Src/hist.c
@@ -1226,7 +1226,15 @@ mod_export int
hend(Eprog prog)
{
LinkList hookargs = newlinklist();
- int flag, save = 1, hookret, stack_pos = histsave_stack_pos;
+ int flag, hookret, stack_pos = histsave_stack_pos;
+ /*
+ * save:
+ * 0: don't save
+ * 1: save normally
+ * -1: save temporarily, delete after next line
+ * -2: save internally but mark for not writing
+ */
+ int save = 1;
char *hf;
DPUTS(stophist != 2 && !(inbufflags & INP_ALIAS) && !chline,
@@ -1279,7 +1287,11 @@ hend(Eprog prog)
}
if (chwordpos <= 2)
save = 0;
- else if (hookret || should_ignore_line(prog))
+ else if (should_ignore_line(prog))
+ save = -1;
+ else if (hookret == 2)
+ save = -2;
+ else if (hookret)
save = -1;
}
if (flag & (HISTFLAG_DONE | HISTFLAG_RECALL)) {
@@ -1325,7 +1337,12 @@ hend(Eprog prog)
if (isset(HISTREDUCEBLANKS))
histreduceblanks();
}
- newflags = save > 0? 0 : HIST_TMPSTORE;
+ if (save == -1)
+ newflags = HIST_TMPSTORE;
+ else if (save == -2)
+ newflags = HIST_NOWRITE;
+ else
+ newflags = 0;
if ((isset(HISTIGNOREDUPS) || isset(HISTIGNOREALLDUPS)) && save > 0
&& hist_ring && histstrcmp(chline, hist_ring->node.nam) == 0) {
/* This history entry compares the same as the previous.
@@ -2590,7 +2607,7 @@ savehistfile(char *fn, int err, int writeflags)
|| he->node.flags & HIST_TMPSTORE)
continue;
if (writeflags & HFILE_SKIPOLD) {
- if (he->node.flags & HIST_OLD)
+ if (he->node.flags & (HIST_OLD|HIST_NOWRITE))
continue;
he->node.flags |= HIST_OLD;
if (writeflags & HFILE_USE_OPTIONS)