poke-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] src/pk-repl.c (pk_repl): Use ~/.poke_history to persist repl com


From: John Darrington
Subject: [PATCH] src/pk-repl.c (pk_repl): Use ~/.poke_history to persist repl commands
Date: Sun, 10 Nov 2019 15:19:57 +0100

---
 src/pk-repl.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/src/pk-repl.c b/src/pk-repl.c
index 22d2e30..1c68ba5 100644
--- a/src/pk-repl.c
+++ b/src/pk-repl.c
@@ -33,6 +33,7 @@
 #endif
 
 #include <signal.h>
+#include <unistd.h>
 
 static void
 banner (void)
@@ -90,6 +91,24 @@ pk_repl (void)
   sigemptyset (&sa.sa_mask);
   sigaction (SIGINT, &sa, 0);
 
+#if defined HAVE_READLINE_HISTORY_H
+  char *poke_history = NULL;
+  /* Load the user's history file ~/.poke_history, if it exists
+     in the HOME directory.  */
+  char *homedir = getenv ("HOME");
+
+  if (homedir != NULL)
+    {
+      poke_history = xmalloc (strlen (homedir)
+                             + strlen ("/.poke_history") + 1);
+      strcpy (poke_history, homedir);
+      strcat (poke_history, "/.poke_history");
+
+      if (access (poke_history, R_OK) == 0)
+       read_history (poke_history);
+    }
+#endif
+
   while (!poke_exit_p)
     {
       int ret;
@@ -118,6 +137,10 @@ pk_repl (void)
         /* Avoid gcc warning here.  */ ;
       free (line);
     }
+#if defined HAVE_READLINE_HISTORY_H
+  if (poke_history)
+    write_history (poke_history);
+#endif
 }
 
 static int saved_point;
-- 
2.11.0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]