rc

[fork] interactive rc shell
Log | Files | Refs | README | LICENSE

commit b234c5153b5f12b82dceefd04865213554a875da
parent ff1290cbb138dd09b0a3ca842f843b8321b4c3fe
Author: Bert Münnich <ber.t@posteo.de>
Date:   Sat, 28 Nov 2015 16:24:41 +0100

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.

Diffstat:
Medit-readline.c | 13++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)

diff --git 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 */ }