From 21016570f4b42a0814134c43e8e27c388856ee5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bert=20M=C3=BCnnich?= Date: Thu, 3 Oct 2019 15:18:16 +0200 Subject: Sort completion matches before quoting them We cannot let readline sort the matches because it gets them after they are quoted and the leading quote character messes up the ordering. --- edit-readline.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'edit-readline.c') diff --git a/edit-readline.c b/edit-readline.c index 8cbac05..dcaa51b 100644 --- a/edit-readline.c +++ b/edit-readline.c @@ -206,10 +206,14 @@ static char *compl_start() { return NULL; } +static int matchcmp(const void *a, const void *b) { + return strcoll(*(const char **)a, *(const char **)b); +} + static rl_compentry_func_t *compentry_func; static char **rc_completion(const char *text, int start, int end) { - size_t i; + size_t i, n; char *t = unquote(text); char **matches = NULL; rl_compentry_func_t *func; @@ -221,14 +225,17 @@ static char **rc_completion(const char *text, int start, int end) { func = compl_func(compl_prefix(start)); matches = rl_completion_matches(t, func); if (matches) { + for (n = 1; matches[n]; n++); + qsort(&matches[1], n - 1, sizeof(matches[0]), matchcmp); if (rl_completion_type != '?') - matches[0] = quote(matches[0], matches[1] != NULL); + matches[0] = quote(matches[0], n > 1); if (rl_completion_type == '*') - for (i = 1; matches[i]; i++) + for (i = 1; i < n; i++) matches[i] = quote(matches[i], 0); } efree(t); rl_attempted_completion_over = 1; + rl_sort_completion_matches = 0; return matches; } -- cgit v1.2.3