readline: Make completion strings always unique
authorHani Benhabiles <kroosec@gmail.com>
Tue, 27 May 2014 22:39:35 +0000 (23:39 +0100)
committerLuiz Capitulino <lcapitulino@redhat.com>
Wed, 11 Jun 2014 14:10:29 +0000 (10:10 -0400)
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

index 8baec555097f11ccb011447dae5f04846085ada4..7214e8407c0f17421431a381f12872569a0aa2b6 100644 (file)
@@ -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);
     }
 }