Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F112058256
D29493.id88499.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
D29493.id88499.diff
View Options
Index: bin/sh/histedit.c
===================================================================
--- bin/sh/histedit.c
+++ bin/sh/histedit.c
@@ -41,6 +41,7 @@
#include <sys/param.h>
#include <sys/stat.h>
#include <dirent.h>
+#include <fcntl.h>
#include <limits.h>
#include <paths.h>
#include <stdio.h>
@@ -78,6 +79,51 @@
static char **sh_matches(const char *, int, int);
static unsigned char sh_complete(EditLine *, int);
+void
+histsave(void)
+{
+ HistEvent he;
+ char *histtmpname = NULL;
+ const char *histfile;
+ int fd;
+ FILE *f;
+
+ /* don't try to save if the history size is 0 */
+ if (hist == NULL || histsizeval() == 0)
+ return;
+ histfile = expandstr("${HISTFILE-${HOME-}/.sh_history}");
+ asprintf(&histtmpname, "%s.XXXXXXXXXX", histfile);
+ if (histtmpname == NULL)
+ return;
+ INTOFF;
+ fd = mkstemp(histtmpname);
+ if (fd < 0 || (f = fdopen(fd, "w")) == NULL) {
+ free(histtmpname);
+ INTON;
+ return;
+ }
+ if (history(hist, &he, H_SAVE_FP, f) < 1 ||
+ rename(histtmpname, histfile) == -1)
+ unlink(histtmpname);
+ fclose(f);
+ free(histtmpname);
+ INTON;
+
+}
+
+static void
+histload(void)
+{
+ const char *histfile;
+ HistEvent he;
+
+ /* don't try to load if the history size is 0 */
+ if (hist == NULL || histsizeval() == 0)
+ return;
+ histfile = expandstr("${HISTFILE-${HOME-}/.sh_history}");
+ history(hist, &he, H_LOAD, histfile);
+}
+
/*
* Set history and editing status. Called whenever the status may
* have changed (figures out what to do).
@@ -101,6 +147,8 @@
sethistsize(histsizeval());
else
out2fmt_flush("sh: can't initialize history\n");
+ /* Load the history */
+ histload();
}
if (editing && !el && isatty(0)) { /* && isatty(2) ??? */
/*
Index: bin/sh/myhistedit.h
===================================================================
--- bin/sh/myhistedit.h
+++ bin/sh/myhistedit.h
@@ -43,4 +43,4 @@
void histedit(void);
void sethistsize(const char *);
void setterm(const char *);
-
+void histsave(void);
Index: bin/sh/trap.c
===================================================================
--- bin/sh/trap.c
+++ bin/sh/trap.c
@@ -535,6 +535,9 @@
flushall();
#if JOBS
setjobctl(0);
+#endif
+#ifndef NO_HISTORY
+ histsave();
#endif
}
if (sig != 0 && sig != SIGSTOP && sig != SIGTSTP && sig != SIGTTIN &&
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Mar 13, 5:43 AM (16 h, 21 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
17130611
Default Alt Text
D29493.id88499.diff (2 KB)
Attached To
Mode
D29493: sh: implement persistent history storage
Attached
Detach File
Event Timeline
Log In to Comment