summaryrefslogtreecommitdiff
path: root/Src/hist.c
diff options
context:
space:
mode:
authorBarton E. Schaefer <schaefer@zsh.org>2014-07-17 19:53:11 -0700
committerBarton E. Schaefer <schaefer@zsh.org>2014-07-17 19:53:11 -0700
commitb63ff19dbf8f220f3ae8ab2ab41058f3149bde1f (patch)
treef88f19b51aac7004fb0c458021eb530878bc2325 /Src/hist.c
parenta8a59f94991fdfd4534442f6e6578c1d6b525f51 (diff)
downloadzsh-b63ff19dbf8f220f3ae8ab2ab41058f3149bde1f.tar.gz
zsh-b63ff19dbf8f220f3ae8ab2ab41058f3149bde1f.zip
32882 (cf. Augie Fackler 32879): correct reload of backslash-continuation lines from history, fix bad history write of events ending with backslashes
Diffstat (limited to 'Src/hist.c')
-rw-r--r--Src/hist.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/Src/hist.c b/Src/hist.c
index 64f88f559..770d559b1 100644
--- a/Src/hist.c
+++ b/Src/hist.c
@@ -2308,8 +2308,7 @@ readhistline(int start, char **bufp, int *bufsiz, FILE *in)
}
else {
buf[len - 1] = '\0';
- if (len > 1 && buf[len - 2] == '\\' &&
- (len < 3 || buf[len - 3] != '\\')) {
+ if (len > 1 && buf[len - 2] == '\\') {
buf[--len - 1] = '\n';
if (!feof(in))
return readhistline(len, bufp, bufsiz, in);
@@ -2618,6 +2617,8 @@ savehistfile(char *fn, int err, int writeflags)
ret = 0;
for (; he && he->histnum <= xcurhist; he = down_histent(he)) {
+ int count_backslashes = 0;
+
if ((writeflags & HFILE_SKIPDUPS && he->node.flags & HIST_DUP)
|| (writeflags & HFILE_SKIPFOREIGN && he->node.flags & HIST_FOREIGN)
|| he->node.flags & HIST_TMPSTORE)
@@ -2649,9 +2650,18 @@ savehistfile(char *fn, int err, int writeflags)
if (*t == '\n')
if ((ret = fputc('\\', out)) < 0)
break;
+ if (*t == '\\')
+ count_backslashes++;
+ else
+ count_backslashes = 0;
if ((ret = fputc(*t, out)) < 0)
break;
}
+ if (ret < 0)
+ break;
+ if (count_backslashes && (count_backslashes % 2 == 0))
+ if ((ret = fputc(' ', out)) < 0)
+ break;
if (ret < 0 || (ret = fputc('\n', out)) < 0)
break;
}