Skip to content

Commit

Permalink
fix cmd completion with dot
Browse files Browse the repository at this point in the history
  • Loading branch information
stsp committed Apr 11, 2024
1 parent cfdff38 commit a098480
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions src/compl.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,24 +121,28 @@ int compl_cmds(const char *prefix, int print, int *r_len, char *r_p)
struct cmpl_s cmpl = { };
glob_t gl_bat, gl_exe, gl_com;
int err, ret = -1, cnt = 0;
const char *p;
const char *suff = ((p = strchr(prefix, '.')) ? "" : "*.");

snprintf(buf, MAXPATH, "%s*.bat", prefix);
if (p && p[1] != '\0')
return compl_fname(prefix, print, r_len, r_p);
snprintf(buf, MAXPATH, "%s%sbat", prefix, suff);
err = glob(buf, GLOB_ERR, NULL, &gl_bat);
if (err && err != GLOB_NOMATCH)
return -1;
if (!err) {
glb_add(&cmpl, &gl_bat);
cnt += gl_bat.gl_pathc;
}
snprintf(buf, MAXPATH, "%s*.exe", prefix);
snprintf(buf, MAXPATH, "%s%sexe", prefix, suff);
err = glob(buf, GLOB_ERR, NULL, &gl_exe);
if (err && err != GLOB_NOMATCH)
goto err1;
if (!err) {
glb_add(&cmpl, &gl_exe);
cnt += gl_exe.gl_pathc;
}
snprintf(buf, MAXPATH, "%s*.com", prefix);
snprintf(buf, MAXPATH, "%s%scom", prefix, suff);
err = glob(buf, GLOB_ERR, NULL, &gl_com);
if (err && err != GLOB_NOMATCH)
goto err2;
Expand All @@ -147,13 +151,15 @@ int compl_cmds(const char *prefix, int print, int *r_len, char *r_p)
cnt += gl_com.gl_pathc;
}

cmpl.compls[cmpl.num].opaque = cmd_table;
cmpl.compls[cmpl.num].get_name = get_cmd_name;
cmpl.compls[cmpl.num].num = CMD_TABLE_COUNT;
cmpl.num++;
if (!p) {
cmpl.compls[cmpl.num].opaque = cmd_table;
cmpl.compls[cmpl.num].get_name = get_cmd_name;
cmpl.compls[cmpl.num].num = CMD_TABLE_COUNT;
cmpl.num++;
cnt += CMD_TABLE_COUNT;
}

ret = do_compl(prefix, print, r_len, r_p, get_compl_name, &cmpl,
CMD_TABLE_COUNT + cnt);
ret = do_compl(prefix, print, r_len, r_p, get_compl_name, &cmpl, cnt);

globfree(&gl_com);
err2:
Expand Down

0 comments on commit a098480

Please sign in to comment.