From f0b7a447bf78c5f9230686b946e8b77cd25153f9 Mon Sep 17 00:00:00 2001 From: Ben Kibbey Date: Sun, 21 Aug 2016 11:22:26 -0400 Subject: [PATCH] pwmc: Remove duplicate history items before appending. --- src/pwmc.c | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/src/pwmc.c b/src/pwmc.c index e9bfbae6..6aad430f 100644 --- a/src/pwmc.c +++ b/src/pwmc.c @@ -1255,6 +1255,36 @@ parse_dotcommand (const char *line, char **result, } #ifdef HAVE_LIBREADLINE +#ifdef HAVE_READLINE_HISTORY +static void +add_history_item (const char *line) +{ + HIST_ENTRY **list, *p = NULL; + int i; + + list = history_list (); + for (i = 0; list && list[i]; i++) + { + if (!strcmp (list[i]->line, line)) + { + p = list[i]; + break; + } + } + + if (p) + { + char *s; + + p = remove_history (i); + s = free_history_entry (p); + free (s); + } + + add_history (line); +} +#endif + static gpg_error_t do_interactive () { @@ -1311,7 +1341,7 @@ do_interactive () } #ifdef HAVE_READLINE_HISTORY - add_history (line); + add_history_item (line); #endif rc = parse_dotcommand (line, &result, &len, inq); free (line); -- 2.11.4.GIT