summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--bin/cash/histedit.c16
-rw-r--r--bin/cash/myhistedit.h1
-rw-r--r--bin/cash/var.c3
3 files changed, 20 insertions, 0 deletions
diff --git a/bin/cash/histedit.c b/bin/cash/histedit.c
index d1e77f51..156800a1 100644
--- a/bin/cash/histedit.c
+++ b/bin/cash/histedit.c
@@ -146,12 +146,19 @@ bad:
 			el_source(el, NULL);
 		}
 	} else {
+		HistEvent he;
+		const char *hf;
+
 		INTOFF;
 		if (el) {	/* no editing if not interactive */
 			el_end(el);
 			el = NULL;
 		}
 		if (hist) {
+			hf = lookupvar("HISTFILE");
+			if (hf != NULL && *hf != '\0')
+				if (history(hist, &he, H_SAVE, hf) == -1)
+					out2fmt_flush("sh: can't save history\n");
 			history_end(hist);
 			hist = NULL;
 		}
@@ -161,6 +168,15 @@ bad:
 
 
 void
+sethistfile(const char *hf)
+{
+	HistEvent he;
+
+	if (hist != NULL && hf != NULL && *hf != '\0')
+		history(hist, &he, H_LOAD, hf);
+}
+
+void
 sethistsize(const char *hs)
 {
 	int histsize;
diff --git a/bin/cash/myhistedit.h b/bin/cash/myhistedit.h
index 8f1305ad..6eebe521 100644
--- a/bin/cash/myhistedit.h
+++ b/bin/cash/myhistedit.h
@@ -39,6 +39,7 @@ extern EditLine *el;
 extern int displayhist;
 
 void histedit(void);
+void sethistfile(const char *);
 void sethistsize(const char *);
 void setpslit(const char *);
 void setterm(const char *);
diff --git a/bin/cash/var.c b/bin/cash/var.c
index d0c01bb7..26c39eb4 100644
--- a/bin/cash/var.c
+++ b/bin/cash/var.c
@@ -85,6 +85,7 @@ struct varinit {
 
 
 #ifndef NO_HISTORY
+struct var vhistfile;
 struct var vhistsize;
 struct var vpslit;
 struct var vterm;
@@ -109,6 +110,8 @@ int forcelocal;
 static const struct varinit varinit[] = {
 	{ &venv, 0, "ENV=${XDG_CONFIG_HOME:-${HOME}/.config}/cash/env.sh", NULL },
 #ifndef NO_HISTORY
+	{ &vhistfile,	VUNSET,				"HISTFILE=",
+	  sethistfile },
 	{ &vhistsize,	VUNSET,				"HISTSIZE=",
 	  sethistsize },
 #endif