From mboxrd@z Thu Jan 1 00:00:00 1970 From: Boris Brezillon Date: Tue, 4 Dec 2018 14:54:52 +0100 Subject: [U-Boot] [PATCH 0/2] cmd: auto-complete args starting with a $ In-Reply-To: <20181204113313.577178ac@bbrezillon> References: <20181203220726.19370-1-boris.brezillon@bootlin.com> <20181204094419.6907C242267@gemini.denx.de> <20181204105448.63b9af8c@bbrezillon> <20181204101431.854D4242267@gemini.denx.de> <20181204113313.577178ac@bbrezillon> Message-ID: <20181204145452.44b35169@bbrezillon> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de On Tue, 4 Dec 2018 11:33:13 +0100 Boris Brezillon 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) {