>From 19b6bbe1b9cb554e4e9897384c59413b5f8ec098 Mon Sep 17 00:00:00 2001 From: Wang Lei Date: Fri, 16 Sep 2011 22:34:49 +0800 Subject: give user a chance not to use history file --- doc/ratpoison.1 | 7 +++++++ doc/ratpoison.texi | 15 ++++++++++----- src/conf.h | 3 +++ src/globals.c | 3 +++ src/globals.h | 3 +++ src/history.c | 32 +++++++++++++++++++++++--------- src/main.c | 9 +++++++-- 7 files changed, 56 insertions(+), 16 deletions(-) diff --git a/doc/ratpoison.1 b/doc/ratpoison.1 index ad7ce83..e120976 100644 --- a/doc/ratpoison.1 +++ b/doc/ratpoison.1 @@ -80,6 +80,7 @@ ratpoison \- window manager without mouse dependency .IR dpy ] .RB [ \-s .IR num ] +.RB [ \-H ] .RB [ \-f .IR file ] .br @@ -88,6 +89,7 @@ ratpoison \- window manager without mouse dependency .IR dpy ] .RB [ \-s .IR num ] +.RB [ \-H ] .RB [ \-i ] .B \-c .IR command @@ -146,6 +148,11 @@ spaces. For example: .br \fBratpoison \-c "echo hello world"\fP +.TP +.B \-H, \-\-no-history +Do not save input history to file. By default, ratpoison will save +input history to file `~/.ratpoison_history'. With this argument, the +history will not save between ratpoison sessions. .SH KEY BINDINGS To avoid conflicts with other programs, all default ratpoison key bindings start with an escape key, per default diff --git a/doc/ratpoison.texi b/doc/ratpoison.texi index 7d9adfd..ed55bea 100644 --- a/doc/ratpoison.texi +++ b/doc/ratpoison.texi @@ -1810,11 +1810,11 @@ backwards through the completions. @end table -All input is stored in the same history list. By default ratpoison has -a history length of 100 entries. This history is saved to the file address@hidden/.ratpoison_history} and is loaded when you start -ratpoison. This means your history sticks between sessions. This -assumes history has not been disabled on compilation. +All input is stored in the same history list. By default ratpoison has a +history length of 100 entries. This history is saved to the file address@hidden/.ratpoison_history} and is loaded when you start ratpoison if +the argument -H is not given. This means your history sticks between +sessions. This assumes history has not been disabled on compilation. @node Command Line Arguments, Startup file, Input, Top @chapter Command Line Arguments @@ -1865,6 +1865,11 @@ in conjunction with the @option{-c} option. @item -f, --file Specify an alternate configuration file. @xref{Startup file}. address@hidden -H, --no-history +Do not save input history to file. By default ratpoison will save input +history to file @file{~/.ratpoison_history}. With this argument, the +input history will not save between ratpoison sessions. + @end table @node Startup file, Command Index, Command Line Arguments, Top 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..ad2c8e6 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; +/* use history file */ +int use_history_file = 1; + static void x_export_selection (void) { diff --git a/src/globals.h b/src/globals.h index e5ba32a..ee5b48f 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; +/* use history file */ +extern int use_history_file; + /* Selection handling globals */ extern rp_xselection selection; void set_selection (char *txt); diff --git a/src/history.c b/src/history.c index 29e1749..125e1e6 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 (use_history_file) { - filename = xmalloc (strlen (homedir) + strlen ("/" HISTORY_FILE) + 1); - sprintf (filename, "%s/" HISTORY_FILE, homedir); + 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; } else { - filename = xstrdup (HISTORY_FILE); + char *filename = xstrdup (HISTORY_NULL); + return filename; } - - return filename; } static const char * @@ -178,6 +186,9 @@ history_load (void) ssize_t linelen; int id; + if (filename == HISTORY_NULL) + return; + for (id = hist_NONE ; id < hist_COUNT ; id++ ) { INIT_LIST_HEAD (&histories[id].head); histories[id].current = &histories[id].head; @@ -220,6 +231,9 @@ history_save (void) FILE *f; struct history_item *item; + if (filename == HISTORY_NULL) + return; + if (!defaults.history_size) return; diff --git a/src/main.c b/src/main.c index 417fc1a..7a3eede 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,7 +338,8 @@ print_help (void) printf ("-s, --screen Only use the specified screen\n"); printf ("-c, --command Send ratpoison a colon-command\n"); printf ("-i, --interactive Execute commands in interactive mode\n"); - printf ("-f, --file Specify an alternative configuration file\n\n"); + printf ("-f, --file Specify an alternative configuration file\n"); + printf ("-H, --no-history Do not save input history\n\n"); printf ("Report bugs to address@hidden"); @@ -598,6 +600,9 @@ main (int argc, char *argv[]) case 'h': print_help (); break; + case 'H': + use_history_file = 0; + break; case 'v': print_version (); break; -- 1.7.6.3