readline: Make completion strings always unique

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>
This commit is contained in:
Hani Benhabiles 2014-05-27 23:39:35 +01:00 committed by Luiz Capitulino
parent e3bb532cc7
commit e70871d8b5

View 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);
}
}