public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Boris Brezillon <boris.brezillon@bootlin.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 0/2] cmd: auto-complete args starting with a $
Date: Tue, 4 Dec 2018 14:54:52 +0100	[thread overview]
Message-ID: <20181204145452.44b35169@bbrezillon> (raw)
In-Reply-To: <20181204113313.577178ac@bbrezillon>

On Tue, 4 Dec 2018 11:33:13 +0100
Boris Brezillon <boris.brezillon@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) {

      parent reply	other threads:[~2018-12-04 13:54 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-03 22:07 [U-Boot] [PATCH 0/2] cmd: auto-complete args starting with a $ Boris Brezillon
2018-12-03 22:07 ` [U-Boot] [PATCH 1/2] common: command: Provide a dollar_complete() helper Boris Brezillon
2018-12-03 22:07 ` [U-Boot] [PATCH 2/2] cmd: mtd: auto-complete args starting with a $ when appropriate Boris Brezillon
2018-12-04  9:44 ` [U-Boot] [PATCH 0/2] cmd: auto-complete args starting with a $ Wolfgang Denk
2018-12-04  9:54   ` Boris Brezillon
2018-12-04 10:14     ` Wolfgang Denk
2018-12-04 10:33       ` Boris Brezillon
2018-12-04 13:00         ` Wolfgang Denk
2018-12-04 13:11           ` Boris Brezillon
2018-12-04 13:54         ` Boris Brezillon [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20181204145452.44b35169@bbrezillon \
    --to=boris.brezillon@bootlin.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox