rc

[fork] interactive rc shell
Log | Files | Refs | README | LICENSE

commit 21016570f4b42a0814134c43e8e27c388856ee5e
parent f58969944e1c582c75240c0ceed8806387bc9841
Author: Bert Münnich <ber.t@posteo.de>
Date:   Thu,  3 Oct 2019 15:18:16 +0200

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.

Diffstat:
Medit-readline.c | 13++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)

diff --git 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; }