From cff85b9a55c7d3f08de9ef9272b97d7fa6212302 Mon Sep 17 00:00:00 2001 From: Phil Jones Date: Tue, 5 Jul 2022 11:03:58 +0100 Subject: Sort results by match position. Search results will now be sorted by history first, then by the position of the match, such that a match at the start of a result will appear before a match later in the result. --- src/compgen.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/compgen.c') diff --git a/src/compgen.c b/src/compgen.c index 84cd323..f656f32 100644 --- a/src/compgen.c +++ b/src/compgen.c @@ -188,6 +188,7 @@ void compgen_history_sort(struct string_vec *programs, struct history *history) free(*res); *res = NULL; string_vec_add(&to_add, history->buf[i].name); + to_add.buf[to_add.count - 1].history_score = history->buf[i].run_count; } /* Sort the vector to push the removed entries to the end. */ @@ -205,7 +206,8 @@ void compgen_history_sort(struct string_vec *programs, struct history *history) /* Add our history to the front in order. */ for (size_t i = 0; i < to_add.count; i++) { - programs->buf[i] = xstrdup(to_add.buf[i]); + programs->buf[i].string = xstrdup(to_add.buf[i].string); + programs->buf[i].history_score = to_add.buf[i].history_score; } string_vec_destroy(&to_add); } -- cgit v1.2.3