diff mbox

[PULL,13/17] readline: Make completion strings always unique

Message ID 1402498262-20521-14-git-send-email-lcapitulino@redhat.com
State New
Headers show

Commit Message

Luiz Capitulino June 11, 2014, 2:50 p.m. UTC
From: Hani Benhabiles <kroosec@gmail.com>

There is no need to clutter the user's choices with repeating the same value
multiple times.

Signed-off-by: Hani Benhabiles <hani@linux.com>
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
 util/readline.c | 6 ++++++
 1 file changed, 6 insertions(+)
diff mbox

Patch

diff --git a/util/readline.c b/util/readline.c
index 8baec55..7214e84 100644
--- a/util/readline.c
+++ b/util/readline.c
@@ -263,6 +263,12 @@  static void readline_hist_add(ReadLineState *rs, const char *cmdline)
 void readline_add_completion(ReadLineState *rs, const char *str)
 {
     if (rs->nb_completions < READLINE_MAX_COMPLETIONS) {
+        int i;
+        for (i = 0; i < rs->nb_completions; i++) {
+            if (!strcmp(rs->completions[i], str)) {
+                return;
+            }
+        }
         rs->completions[rs->nb_completions++] = g_strdup(str);
     }
 }