[PATCH]give use a chance not to use history file

Wang Lei <[email protected]>
Newsgroups gmane.comp.window-managers.ratpoison.devel
Message-ID <[email protected]>
Hi, all.

I'm a new programmer. I use ratpoison, and very like it. So I'm trying
to do something helpful.

I do not use colon or exec often, and don't like to see
.ratpoison_history. So this patch is out. Is this the right way to do?


-- 
Regards,
Lei

_______________________________________________
Ratpoison-devel mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/ratpoison-devel
0001-give-user-a-chance-not-to-use-history-file.patch (application/octet-stream, 3.8 KB)
From 923e4bcc69fef9f8bd2bc2e87e955aacb5cf74d0 Mon Sep 17 00:00:00 2001
From: Wang Lei <[email protected]>
Date: Sat, 27 Aug 2011 11:50:22 +0800
Subject: [PATCH] give user a chance not to use history file

---
 src/conf.h    |    3 +++
 src/globals.c |    3 +++
 src/globals.h |    3 +++
 src/history.c |   28 ++++++++++++++++++----------
 src/main.c    |    7 ++++++-
 5 files changed, 33 insertions(+), 11 deletions(-)

diff --git a/src/conf.h b/src/conf.h
index 708b688..fcb1ad5 100644
--- a/src/conf.h
+++ b/src/conf.h
@@ -110,6 +110,9 @@
 /* The default filename in which to store the history */
 #define HISTORY_FILE ".ratpoison_history"
 
+/* If the user don't like history file, drop cache to /dev/null */
+#define HISTORY_NULL "/dev/null"
+
 /* Use a visual bell in the input window */
 #define VISUAL_BELL 1
 
diff --git a/src/globals.c b/src/globals.c
index 3029aef..65206e0 100644
--- a/src/globals.c
+++ b/src/globals.c
@@ -87,6 +87,9 @@ struct numset *rp_frame_numset;
 /* The X11 selection globals */
 rp_xselection selection;
 
+/* do not use history file */
+int no_history = 0;
+
 static void
 x_export_selection (void)
 {
diff --git a/src/globals.h b/src/globals.h
index e5ba32a..c585763 100644
--- a/src/globals.h
+++ b/src/globals.h
@@ -197,6 +197,9 @@ extern struct numset *rp_frame_numset;
 extern struct list_head rp_frame_undos;
 extern struct list_head rp_frame_redos;
 
+/* do not use history file */
+extern int no_history;
+
 /* Selection handling globals */
 extern rp_xselection selection;
 void set_selection (char *txt);
diff --git a/src/history.c b/src/history.c
index 29e1749..9410773 100644
--- a/src/history.c
+++ b/src/history.c
@@ -32,20 +32,28 @@
 static char *
 get_history_filename (void)
 {
-  char *homedir = getenv ("HOME");
-  char *filename;
-
-  if (homedir)
+  if (no_history) 
     {
-      filename = xmalloc (strlen (homedir) + strlen ("/" HISTORY_FILE) + 1);
-      sprintf (filename, "%s/" HISTORY_FILE, homedir);
+      char *filename = xstrdup (HISTORY_NULL);
+      return filename;
     }
-  else
+  else 
     {
-      filename = xstrdup (HISTORY_FILE);
+      char *homedir = getenv ("HOME");
+      char *filename;
+
+      if (homedir)
+        {
+          filename = xmalloc (strlen (homedir) + strlen ("/" HISTORY_FILE) + 1);
+          sprintf (filename, "%s/" HISTORY_FILE, homedir);
+        }
+      else
+        {
+          filename = xstrdup (HISTORY_FILE);
+        }
+
+      return filename;
     }
-
-  return filename;
 }
 
 static const char *
diff --git a/src/main.c b/src/main.c
index 417fc1a..5ae0f20 100644
--- a/src/main.c
+++ b/src/main.c
@@ -53,9 +53,10 @@ static struct option ratpoison_longopts[] =
     {"display", required_argument,      0,      'd'},
     {"screen",  required_argument,      0,      's'},
     {"file",            required_argument,      0,      'f'},
+    {"no-history", no_argument,         0,      'H'},
     {0,         0,                      0,      0} };
 
-static char ratpoison_opts[] = "hvic:d:s:f:";
+static char ratpoison_opts[] = "hvic:d:s:f:H";
 
 void
 fatal (const char *msg)
@@ -337,6 +338,7 @@ print_help (void)
   printf ("-s, --screen <num>    Only use the specified screen\n");
   printf ("-c, --command <cmd>   Send ratpoison a colon-command\n");
   printf ("-i, --interactive     Execute commands in interactive mode\n");
+  printf ("-H, --no-history      Do not save command history\n");
   printf ("-f, --file <file>     Specify an alternative configuration file\n\n");
 
   printf ("Report bugs to [email protected]\n\n");
@@ -598,6 +600,9 @@ main (int argc, char *argv[])
         case 'h':
           print_help ();
           break;
+        case 'H':
+          no_history = 1;
+          break;
         case 'v':
           print_version ();
           break;
-- 
1.7.5.4
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.