From aeea5a2e2d36e6e6c57063835a1fb1a17f5c60fc Mon Sep 17 00:00:00 2001 From: Ananth Date: Sat, 17 Apr 2021 20:46:47 -0700 Subject: [PATCH 2/8] tag history entry as private --- bashhist.c | 15 +++++++++++---- lib/readline/doc/hstech.texi | 15 ++++++++++++--- lib/readline/history.c | 28 ++++++++++++++++++++++------ lib/readline/history.h | 4 +++- 4 files changed, 48 insertions(+), 14 deletions(-) diff --git a/bashhist.c b/bashhist.c index eb6471a..6190018 100644 --- a/bashhist.c +++ b/bashhist.c @@ -599,7 +599,7 @@ pre_process_line (line, print_changes, addit) { # if defined (READLINE) if (expanded == 2 && rl_dispatching == 0 && *history_value) -# else +# else if (expanded == 2 && *history_value) # endif /* !READLINE */ maybe_add_history (history_value); @@ -793,7 +793,7 @@ check_add_history (line, force) remove other matching lines from the history. */ if (history_control & HC_ERASEDUPS) hc_erasedups (line); - + if (force) { really_add_history (line); @@ -859,7 +859,7 @@ bash_syslog_history (line) } } #endif - + /* Add a line to the history list. The variable COMMAND_ORIENTED_HISTORY controls the style of history remembering; when non-zero, and LINE is not the first line of a @@ -961,7 +961,14 @@ really_add_history (line) { hist_last_line_added = 1; hist_last_line_pushed = 0; - add_history (line); + if(private_history_mode) + { + add_private_history(line); + } + else + { + add_history (line); + } history_lines_this_session++; } diff --git a/lib/readline/doc/hstech.texi b/lib/readline/doc/hstech.texi index 7ac1195..7a5b4c6 100644 --- a/lib/readline/doc/hstech.texi +++ b/lib/readline/doc/hstech.texi @@ -46,7 +46,7 @@ History Interactively}. Many programs read input from the user a line at a time. The @sc{gnu} History library is able to keep track of those lines, associate arbitrary data with each line, and utilize information from previous lines in -composing new ones. +composing new ones. A programmer using the History library has available functions for remembering lines on a history list, associating arbitrary data @@ -171,6 +171,15 @@ If the maximum number of history entries has been set using that maximum, the oldest history entry is removed. @end deftypefun +@deftypefun void add_private_history (const char *string) +Place @var{string} at the end of the history list. The associated data +field (if any) is set to @code{NULL}. +If the maximum number of history entries has been set using +@code{stifle_history()}, and the new number of history entries would exceed +that maximum, the oldest history entry is removed. History added by this is not +written to the history file +@end deftypefun + @deftypefun void add_history_time (const char *string) Change the time stamp associated with the most recent history entry to @var{string}. @@ -311,8 +320,8 @@ offset. The search is anchored: matching lines must begin with @var{string}. If @var{direction} is less than 0, then the search is through previous entries, otherwise through subsequent entries. If @var{string} is found, then the -current history index is set to that entry, and the return value is 0. -Otherwise, nothing is changed, and a -1 is returned. +current history index is set to that entry, and the return value is 0. +Otherwise, nothing is changed, and a -1 is returned. @end deftypefun @deftypefun int history_search_pos (const char *string, int direction, int pos) diff --git a/lib/readline/history.c b/lib/readline/history.c index 67158b1..409daac 100644 --- a/lib/readline/history.c +++ b/lib/readline/history.c @@ -165,7 +165,7 @@ history_set_pos (int pos) history_offset = pos; return (1); } - + /* Return the current history array. The caller has to be careful, since this is the actual array of data, and could be bashed or made corrupt easily. The array is terminated with a NULL pointer. */ @@ -226,6 +226,7 @@ alloc_history_entry (char *string, char *ts) temp->line = string ? savestring (string) : string; temp->data = (char *)NULL; temp->timestamp = ts; + temp->private = 0; return temp; } @@ -268,8 +269,7 @@ hist_inittime (void) /* Place STRING at the end of the history list. The data field is set to NULL. */ -void -add_history (const char *string) +static void common_add_history (const char *string, int private) { HIST_ENTRY *temp; int new_length; @@ -320,12 +320,28 @@ add_history (const char *string) } temp = alloc_history_entry ((char *)string, hist_inittime ()); + if(private) + { + temp->private = 1; + } the_history[new_length] = (HIST_ENTRY *)NULL; the_history[new_length - 1] = temp; history_length = new_length; } + +void add_history(const char *string) +{ + common_add_history(string, 0); +} + +void add_private_history(const char *string) +{ + common_add_history(string, 1); +} + + /* Change the time stamp of the most recent history entry to STRING. */ void add_history_time (const char *string) @@ -373,7 +389,7 @@ copy_history_entry (HIST_ENTRY *hist) return ret; } - + /* Make the history entry at WHICH have LINE and DATA. This returns the old entry so you can dispose of the data. In the case of an invalid WHICH, a NULL pointer is returned. */ @@ -470,8 +486,8 @@ _hs_replace_history_data (int which, histdata_t *old, histdata_t *new) entry = the_history[last]; entry->data = new; /* XXX - we don't check entry->old */ } -} - +} + /* Remove history element WHICH from the history. The removed element is returned to you so you can free the line, data, and containing structure. */ diff --git a/lib/readline/history.h b/lib/readline/history.h index cc3de29..4d1583e 100644 --- a/lib/readline/history.h +++ b/lib/readline/history.h @@ -47,6 +47,7 @@ typedef struct _hist_entry { char *line; char *timestamp; /* char * rather than time_t for read/write */ histdata_t data; + int private; } HIST_ENTRY; /* Size of the history-library-managed space in history entry HS. */ @@ -81,6 +82,7 @@ extern void history_set_history_state PARAMS((HISTORY_STATE *)); /* Place STRING at the end of the history list. The associated data field (if any) is set to NULL. */ extern void add_history PARAMS((const char *)); +extern void add_private_history PARAMS((const char *)); /* Change the timestamp associated with the most recent history entry to STRING. */ @@ -133,7 +135,7 @@ extern HIST_ENTRY **history_list PARAMS((void)); /* Returns the number which says what history element we are now looking at. */ extern int where_history PARAMS((void)); - + /* Return the history entry at the current position, as determined by history_offset. If there is no entry there, return a NULL pointer. */ extern HIST_ENTRY *current_history PARAMS((void)); -- 2.31.1