summaryrefslogtreecommitdiff
path: root/src/compgen.c
diff options
context:
space:
mode:
authorPhil Jones <philj56@gmail.com>2022-07-05 11:03:58 +0100
committerPhil Jones <philj56@gmail.com>2022-07-05 11:03:58 +0100
commitcff85b9a55c7d3f08de9ef9272b97d7fa6212302 (patch)
tree5d0d9b147ec2f2ec63a86f0e26fceee9e03c8452 /src/compgen.c
parente062dc7ca2bb70561b11674428939057832158a9 (diff)
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.
Diffstat (limited to 'src/compgen.c')
-rw-r--r--src/compgen.c4
1 files changed, 3 insertions, 1 deletions
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);
}