Skip to content

cmd: auto-complete args starting with a $

Boris Brezillon u-boot 1 version New

Get series with b4
b4 am 20181204145452.44b35169@bbrezillon

Versions newest first

  1. v1 Latest0 of 2 patches 0 repliesNew

Patches in v1 No applies recorded yet

None of the 2 patches the cover letter announces are in this archive.

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [U-Boot] [PATCH 0/2] cmd: auto-complete args starting with a $
Quoted 10 lines · On Tue, 4 Dec 2018 11:33:13 +0100 Boris Brezillon…
Quoted 7 lines

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---

common/command.c +8 -3
index 754ab9bbc396..b9a44d4ea7a8 100644
@@ -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) {