summaryrefslogtreecommitdiff
path: root/src/compgen.c
diff options
context:
space:
mode:
authorPhil Jones <philj56@gmail.com>2022-06-10 19:36:29 +0100
committerPhil Jones <philj56@gmail.com>2022-06-10 19:36:29 +0100
commit7c31982244f179cb2f51bb1d81b21ad4efd649ba (patch)
tree07c612f81b6b5a15aa2c0587fdee7077ceaeba36 /src/compgen.c
parenta6ac47fb763fd4448c0269e274f061226fa0f10a (diff)
Various small changes.
- Split the compgen and history sorting parts of compgen(), for future dmenu-like work. - Add a separate tofi-compgen executable. - Remove harfbuzz-glib usage, as we shouldn't be doing any complicated unicode stuff.
Diffstat (limited to 'src/compgen.c')
-rw-r--r--src/compgen.c20
1 files changed, 12 insertions, 8 deletions
diff --git a/src/compgen.c b/src/compgen.c
index 3ab228a..b0ea44d 100644
--- a/src/compgen.c
+++ b/src/compgen.c
@@ -9,7 +9,7 @@
#include "string_vec.h"
#include "xmalloc.h"
-struct string_vec compgen(struct history *history)
+struct string_vec compgen()
{
log_debug("Retrieving PATH.\n");
const char *env_path = getenv("PATH");
@@ -54,6 +54,11 @@ struct string_vec compgen(struct history *history)
log_debug("Making unique.\n");
string_vec_uniq(&programs);
+ return programs;
+}
+
+void compgen_history_sort(struct string_vec *programs, struct history *history)
+{
log_debug("Moving already known programs to the front.\n");
/*
* Remove any programs in our history from the generated list, and
@@ -63,7 +68,7 @@ struct string_vec compgen(struct history *history)
*/
struct string_vec to_add = string_vec_create();
for (size_t i = 0; i < history->count; i++) {
- char **res = string_vec_find(&programs, history->buf[i].name);
+ char **res = string_vec_find(programs, history->buf[i].name);
if (res == NULL) {
continue;
}
@@ -73,7 +78,7 @@ struct string_vec compgen(struct history *history)
}
/* Sort the vector to push the removed entries to the end. */
- string_vec_sort(&programs);
+ string_vec_sort(programs);
/*
* Move the results down by the number of items we want to add. There's
@@ -81,14 +86,13 @@ struct string_vec compgen(struct history *history)
* many items.
*/
memmove(
- &programs.buf[to_add.count],
- programs.buf,
- (programs.count - to_add.count) * sizeof(programs.buf[0]));
+ &programs->buf[to_add.count],
+ programs->buf,
+ (programs->count - to_add.count) * sizeof(programs->buf[0]));
/* 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] = xstrdup(to_add.buf[i]);
}
string_vec_destroy(&to_add);
- return programs;
}