degesch: fix option completion

This commit is contained in:
Přemysl Eric Janouch 2015-05-07 07:47:58 +02:00
parent e3f1bcecae
commit 715def6555
1 changed files with 14 additions and 5 deletions

View File

@ -5212,12 +5212,21 @@ complete_option (struct app_context *ctx, struct completion *data,
struct str_vector options;
str_vector_init (&options);
// Wildcard expansion is an interesting side-effect
char *x = xstrdup_printf ("%s*", word);
dump_matching_options (ctx, x, &options);
free (x);
config_dump (ctx->config.root, &options);
str_vector_sort (&options);
str_vector_add_vector (output, options.vector);
// Wildcard expansion is an interesting side-effect
char *mask = xstrdup_printf ("%s*", word);
for (size_t i = 0; i < options.len; i++)
{
const char *line = options.vector[i];
char *key = xstrndup (line, strcspn (line, " "));
if (!fnmatch (mask, key, 0))
str_vector_add_owned (output, key);
else
free (key);
}
free (mask);
str_vector_free (&options);
}