diff options
| author | Bert Münnich <ber.t@posteo.de> | 2015-11-28 16:24:41 +0100 |
|---|---|---|
| committer | Bert Münnich <ber.t@posteo.de> | 2018-12-29 19:19:11 +0100 |
| commit | b234c5153b5f12b82dceefd04865213554a875da (patch) | |
| tree | f8d81b627d9d5e5e4a6c739806f323b8c5c220a6 | |
| parent | ff1290cbb138dd09b0a3ca842f843b8321b4c3fe (diff) | |
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.
| -rw-r--r-- | edit-readline.c | 13 |
1 files changed, 12 insertions, 1 deletions
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 */ } |