From b234c5153b5f12b82dceefd04865213554a875da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bert=20M=C3=BCnnich?= Date: Sat, 28 Nov 2015 16:24:41 +0100 Subject: Prevent duplicate lines in readline history Before appending a new line to the readline history, remove all prior lines in the history, which are an exact duplicate of it. --- edit-readline.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'edit-readline.c') diff --git a/edit-readline.c b/edit-readline.c index 47c8db5..2c3f483 100644 --- a/edit-readline.c +++ b/edit-readline.c @@ -333,8 +333,19 @@ char *edit_alloc(void *cookie, size_t *count) { if (c->buffer) { *count = strlen(c->buffer); - if (*count) + if (*count) { + history_set_pos(history_length); + while (history_search_prefix(c->buffer, -1) == 0) { + HIST_ENTRY *e = current_history(); + if (e != NULL && e->line[*count] == '\0') { + if ((e = remove_history(where_history()))) + free_history_entry(e); + } + if (!previous_history()) + break; + } add_history(c->buffer); + } c->buffer[*count] = '\n'; ++*count; /* include the \n */ } -- cgit v1.2.3