diff options
author | Ron Yorston <rmy@pobox.com> | 2020-12-11 12:34:21 +0000 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2020-12-16 09:38:25 +0100 |
commit | 8baa643a3445882ec9c39dfcabb7374081c13aee (patch) | |
tree | d0542acb9a36d2bcabe82e362f34b8d10fa8dee2 | |
parent | 8506dd673030539b2890dd617f885ec20f1e8a7d (diff) | |
download | busybox-w32-8baa643a3445882ec9c39dfcabb7374081c13aee.tar.gz busybox-w32-8baa643a3445882ec9c39dfcabb7374081c13aee.tar.bz2 busybox-w32-8baa643a3445882ec9c39dfcabb7374081c13aee.zip |
lineedit: match local directories when searching PATH
When tab-completing a command we search PATH if the partial text
doesn't include a slash. Also match subdirectories of the current
directory, in case the user intends to run a binary from one of
them.
function old new delta
complete_cmd_dir_file 894 917 +23
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/0 up/down: 23/0) Total: 23 bytes
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | libbb/lineedit.c | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/libbb/lineedit.c b/libbb/lineedit.c index d64d7d0c2..5eb701f00 100644 --- a/libbb/lineedit.c +++ b/libbb/lineedit.c | |||
@@ -753,7 +753,7 @@ static int path_parse(char ***p) | |||
753 | return 1; | 753 | return 1; |
754 | 754 | ||
755 | tmp = (char*)pth; | 755 | tmp = (char*)pth; |
756 | npth = 1; /* path component count */ | 756 | npth = 2; /* path component count */ |
757 | while (1) { | 757 | while (1) { |
758 | tmp = strchr(tmp, ':'); | 758 | tmp = strchr(tmp, ':'); |
759 | if (!tmp) | 759 | if (!tmp) |
@@ -776,6 +776,8 @@ static int path_parse(char ***p) | |||
776 | break; /* :<empty> */ | 776 | break; /* :<empty> */ |
777 | res[npth++] = tmp; | 777 | res[npth++] = tmp; |
778 | } | 778 | } |
779 | /* special case: match subdirectories of the current directory */ | ||
780 | res[npth++] = NULL; | ||
779 | return npth; | 781 | return npth; |
780 | } | 782 | } |
781 | 783 | ||
@@ -843,6 +845,11 @@ static NOINLINE unsigned complete_cmd_dir_file(const char *command, int type) | |||
843 | struct stat st; | 845 | struct stat st; |
844 | char *found; | 846 | char *found; |
845 | 847 | ||
848 | if (paths[i] == NULL) { | ||
849 | type = FIND_DIR_ONLY; | ||
850 | paths[i] = (char *)"."; | ||
851 | } | ||
852 | |||
846 | dir = opendir(paths[i]); | 853 | dir = opendir(paths[i]); |
847 | if (!dir) | 854 | if (!dir) |
848 | continue; /* don't print an error */ | 855 | continue; /* don't print an error */ |