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>
This commit is contained in:
parent
8506dd6730
commit
8baa643a34
@ -753,7 +753,7 @@ static int path_parse(char ***p)
|
|||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
tmp = (char*)pth;
|
tmp = (char*)pth;
|
||||||
npth = 1; /* path component count */
|
npth = 2; /* path component count */
|
||||||
while (1) {
|
while (1) {
|
||||||
tmp = strchr(tmp, ':');
|
tmp = strchr(tmp, ':');
|
||||||
if (!tmp)
|
if (!tmp)
|
||||||
@ -776,6 +776,8 @@ static int path_parse(char ***p)
|
|||||||
break; /* :<empty> */
|
break; /* :<empty> */
|
||||||
res[npth++] = tmp;
|
res[npth++] = tmp;
|
||||||
}
|
}
|
||||||
|
/* special case: match subdirectories of the current directory */
|
||||||
|
res[npth++] = NULL;
|
||||||
return npth;
|
return npth;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -843,6 +845,11 @@ static NOINLINE unsigned complete_cmd_dir_file(const char *command, int type)
|
|||||||
struct stat st;
|
struct stat st;
|
||||||
char *found;
|
char *found;
|
||||||
|
|
||||||
|
if (paths[i] == NULL) {
|
||||||
|
type = FIND_DIR_ONLY;
|
||||||
|
paths[i] = (char *)".";
|
||||||
|
}
|
||||||
|
|
||||||
dir = opendir(paths[i]);
|
dir = opendir(paths[i]);
|
||||||
if (!dir)
|
if (!dir)
|
||||||
continue; /* don't print an error */
|
continue; /* don't print an error */
|
||||||
|
Loading…
Reference in New Issue
Block a user