From 715def65554892b0f75861391823ed0295492e71 Mon Sep 17 00:00:00 2001
From: Přemysl Janouch
Date: Thu, 7 May 2015 07:47:58 +0200
Subject: degesch: fix option completion
---
degesch.c | 19 ++++++++++++++-----
1 file changed, 14 insertions(+), 5 deletions(-)
diff --git a/degesch.c b/degesch.c
index 8b4a30b..e00a224 100644
--- a/degesch.c
+++ b/degesch.c
@@ -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);
}
--
cgit v1.2.3-70-g09d2