This completer returns command names and group keywords as well. --- tools/virsh.c | 43 ++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 42 insertions(+), 1 deletions(-) diff --git a/tools/virsh.c b/tools/virsh.c index 6a63363..f30d51c 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -712,6 +712,46 @@ complt_listAllDomains(const char *text, int state) return complt_listDomainsFlags(text, state, ACTIVE | INACTIVE); } +static char * +complt_listCmdsAndGroups(const char *text, int state) +{ + static int len = 0; + static int grp_index = 0; + static const char *ret = NULL; + static const vshCmdGrp *g = NULL; + static const vshCmdDef *c = NULL; + + if (!state) { + len = strlen(text); + grp_index = 0; + g = cmdGroups; + c = g->commands; + } + + while ((ret = cmdGroups[grp_index].keyword)) { + grp_index++; + + if (STRNEQLEN(ret, text, len)) + continue; + + return vshStrdup(NULL, ret); + } + + while(g->name) { + while ((ret = c->name)) { + c++; + if (STRNEQLEN(ret, text, len)) + continue; + + return vshStrdup(NULL, ret); + } + g++; + c = g->commands; + } + + return NULL; +} + /* --------------- * Commands * --------------- @@ -12002,7 +12042,8 @@ static const vshCmdDef virshCmds[] = { {"cd", cmdCd, opts_cd, info_cd, VSH_CMD_FLAG_NOCONNECT, NULL}, {"echo", cmdEcho, opts_echo, info_echo, VSH_CMD_FLAG_NOCONNECT, NULL}, {"exit", cmdQuit, NULL, info_quit, VSH_CMD_FLAG_NOCONNECT, NULL}, - {"help", cmdHelp, opts_help, info_help, VSH_CMD_FLAG_NOCONNECT, NULL}, + {"help", cmdHelp, opts_help, info_help, + VSH_CMD_FLAG_NOCONNECT, complt_listCmdsAndGroups}, {"pwd", cmdPwd, NULL, info_pwd, VSH_CMD_FLAG_NOCONNECT, NULL}, {"quit", cmdQuit, NULL, info_quit, VSH_CMD_FLAG_NOCONNECT, NULL}, {NULL, NULL, NULL, NULL, 0, NULL} -- 1.7.5.rc3 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list