1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2025-10-24 04:50:27 +02:00

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.
This commit is contained in:
Peter Stephenson 2013-10-17 10:14:25 +01:00
parent a8f736b4cf
commit 73ececfd01
5 changed files with 49 additions and 7 deletions

View file

@ -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)

View file

@ -1894,6 +1894,7 @@ struct histent {
#define HIST_DUP 0x00000008 /* Command duplicates a later line */
#define HIST_FOREIGN 0x00000010 /* Command came from another shell */
#define HIST_TMPSTORE 0x00000020 /* Kill when user enters another cmd */
#define HIST_NOWRITE 0x00000040 /* Keep internally but don't write */
#define GETHIST_UPWARD (-1)
#define GETHIST_DOWNWARD 1