aboutsummaryrefslogtreecommitdiff
path: root/vis-lua.c
diff options
context:
space:
mode:
authorRandy Palamar <randy@rnpnr.xyz>2025-12-05 14:53:04 -0700
committerRandy Palamar <randy@rnpnr.xyz>2025-12-05 17:29:12 -0700
commit402bc58112c5881d814ee6b04559d7369d455a9f (patch)
treef9b028b2c8e4b8b65da5055ebd2ed9c31f375cdd /vis-lua.c
parent1baf9352ae760f576f2ad213256649bdb266ddfb (diff)
downloadvis-402bc58112c5881d814ee6b04559d7369d455a9f.tar.gz
vis-402bc58112c5881d814ee6b04559d7369d455a9f.tar.xz
vis-lua: complete_command: utilize map_prefix() instead of grep
we already have a function for filtering by a prefix. No need for snprintf and extra grep process for filtering. also use simpler buffer_append for appending instead of going through string formatting
Diffstat (limited to 'vis-lua.c')
-rw-r--r--vis-lua.c8
1 files changed, 3 insertions, 5 deletions
diff --git a/vis-lua.c b/vis-lua.c
index 99d9746..7986503 100644
--- a/vis-lua.c
+++ b/vis-lua.c
@@ -1161,13 +1161,11 @@ static int complete_command(lua_State *L) {
Vis *vis = obj_ref_check(L, 1, "vis");
const char *prefix = luaL_checkstring(L, 2);
char *out = NULL, *err = NULL;
- char cmd[32];
- int max_prefix_len = sizeof(cmd) - sizeof("grep '^' | vis-menu -b"); // including NUL
- snprintf(cmd, sizeof(cmd), "grep '^%.*s' | vis-menu -b", max_prefix_len, prefix);
Buffer buf = {0};
- vis_print_cmds(vis, &buf);
- int status = vis_pipe_buf_collect(vis, buffer_content0(&buf), (const char*[]){cmd, NULL}, &out, &err, false);
+ vis_print_cmds(vis, &buf, prefix);
+ int status = vis_pipe_buf_collect(vis, buffer_content0(&buf), (const char*[]){"vis-menu", "-b", 0},
+ &out, &err, false);
lua_pushinteger(L, status);
if (out) lua_pushstring(L, out);