lineedit: search applets as well as PATH for tab completion
authorRon Yorston <rmy@frippery.org>
Fri, 29 May 2015 10:31:40 +0000 (11:31 +0100)
committerDenys Vlasenko <vda.linux@googlemail.com>
Fri, 30 Oct 2015 18:49:33 +0000 (19:49 +0100)
In standalone shell mode search the applet table as well as PATH
when tab completing a command.

Use a stupid linear search:  we're also about to read all the
directories on PATH so efficiency isn't a big concern.

function                                             old     new   delta
add_match                                              -      53     +53
complete_cmd_dir_file                                687     724     +37
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 1/0 up/down: 90/0)               Total: 90 bytes

Signed-off-by: Ron Yorston <rmy@frippery.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
libbb/lineedit.c

index a83e07c0cda1db6fcbf086267af56dae3e69e295..2ddb2b6e9632342ecfddd0952f2b605acec8f4f9 100644 (file)
@@ -47,7 +47,8 @@
  * It stems from simplistic "cmdedit_y = cmdedit_prmt_len / cmdedit_termw"
  * calculation of how many lines the prompt takes.
  */
-#include "libbb.h"
+#include "busybox.h"
+#include "NUM_APPLETS.h"
 #include "unicode.h"
 #ifndef _POSIX_VDISABLE
 # define _POSIX_VDISABLE '\0'
@@ -774,6 +775,20 @@ static NOINLINE unsigned complete_cmd_dir_file(const char *command, int type)
        }
        pf_len = strlen(pfind);
 
+#if ENABLE_FEATURE_SH_STANDALONE && NUM_APPLETS != 1
+       if (type == FIND_EXE_ONLY) {
+               const char *p = applet_names;
+
+               i = 0;
+               while (i < NUM_APPLETS) {
+                       if (strncmp(pfind, p, pf_len) == 0)
+                               add_match(xstrdup(p));
+                       p += strlen(p) + 1;
+                       i++;
+               }
+       }
+#endif
+
        for (i = 0; i < npaths; i++) {
                DIR *dir;
                struct dirent *next;