diff --git a/client/command.c b/client/command.c index 1c42f8e2..a59ff2c2 100644 --- a/client/command.c +++ b/client/command.c @@ -253,6 +253,31 @@ done: return matches; } +char *command_entity_arg_completion(const char *text, int state, + const struct command *command_list) +{ + static size_t index; + static size_t len; + const char *cmd; + + if (!state) { + index = 0; + len = strlen(text); + } + + while ((cmd = command_list[index].cmd)) { + if (!command_list[index++].entity) + continue; + + if (strncmp(cmd, text, len)) + continue; + + return l_strdup(cmd); + } + + return NULL; +} + static void execute_cmd(const char *family, const char *entity, const struct command *cmd, char *args) { diff --git a/client/command.h b/client/command.h index 5e849981..874053e5 100644 --- a/client/command.h +++ b/client/command.h @@ -41,6 +41,8 @@ struct command_family { }; char **command_completion(const char *text, int start, int end); +char *command_entity_arg_completion(const char *text, int state, + const struct command *command_list); void command_process_prompt(char *prompt);