[U-Boot] [PATCH 0/2] cmd: auto-complete args starting with a $
Boris Brezillon
boris.brezillon at bootlin.com
Tue Dec 4 13:54:52 UTC 2018
On Tue, 4 Dec 2018 11:33:13 +0100
Boris Brezillon <boris.brezillon at bootlin.com> wrote:
> >
> > i. e. this is a feature of the shell and not of any command.
> > Implementing this a zillion times for each of the commands in
> > inacceptable. Also, implementing it for one command and not for
> > another makese no sense - that would violate the Principle of Least
> > Surprise, as you have something which looks convenient but does not
> > work everywhere.
>
> Okay, I understand. I can try to hook that up at the common/command.c
> level.
I thought it would be much more complicated: here is the diff adding $
auto-completion for everyone. The only drawback I see with this approach
is that cmd/sub-cmd arg auto-completion cannot be bound to cmd->maxargs
anymore, but I guess that's acceptable.
--->8---
diff --git a/common/command.c b/common/command.c
index 754ab9bbc396..b9a44d4ea7a8 100644
--- a/common/command.c
+++ b/common/command.c
@@ -373,9 +373,14 @@ int cmd_auto_complete(const char *const prompt, char *buf, int *np, int *colp)
/* separate into argv */
argc = make_argv(tmp_buf, sizeof(argv)/sizeof(argv[0]), argv);
- /* do the completion and return the possible completions */
- i = complete_cmdv(argc, argv, last_char,
- sizeof(cmdv) / sizeof(cmdv[0]), cmdv);
+ /* first try a $ completion */
+ i = dollar_complete(argc, argv, last_char,
+ sizeof(cmdv) / sizeof(cmdv[0]), cmdv);
+ if (!i) {
+ /* do the completion and return the possible completions */
+ i = complete_cmdv(argc, argv, last_char,
+ sizeof(cmdv) / sizeof(cmdv[0]), cmdv);
+ }
/* no match; bell and out */
if (i == 0) {
More information about the U-Boot
mailing list