summaryrefslogtreecommitdiff
path: root/edit-readline.c
diff options
context:
space:
mode:
authorBert Münnich <ber.t@posteo.de>2019-10-03 15:18:16 +0200
committerBert Münnich <ber.t@posteo.de>2019-12-06 17:57:34 +0100
commit21016570f4b42a0814134c43e8e27c388856ee5e (patch)
tree49addf5f60958f8c419c8c0520573273d92f5355 /edit-readline.c
parentf58969944e1c582c75240c0ceed8806387bc9841 (diff)
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 (limited to 'edit-readline.c')
-rw-r--r--edit-readline.c13
1 files changed, 10 insertions, 3 deletions
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;
}