complete: add executable file support
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
This commit is contained in:
parent
7e3a16ef14
commit
9492976bc8
|
@ -26,7 +26,7 @@
|
||||||
#include <command.h>
|
#include <command.h>
|
||||||
#include <environment.h>
|
#include <environment.h>
|
||||||
|
|
||||||
static int file_complete(struct string_list *sl, char *instr)
|
static int file_complete(struct string_list *sl, char *instr, int exec)
|
||||||
{
|
{
|
||||||
char *path = strdup(instr);
|
char *path = strdup(instr);
|
||||||
struct stat s;
|
struct stat s;
|
||||||
|
@ -46,15 +46,20 @@ static int file_complete(struct string_list *sl, char *instr)
|
||||||
if (!strcmp(d->d_name, ".") || !strcmp(d->d_name, ".."))
|
if (!strcmp(d->d_name, ".") || !strcmp(d->d_name, ".."))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (!strncmp(base, d->d_name, strlen(base))) {
|
if (strncmp(base, d->d_name, strlen(base)))
|
||||||
strcpy(tmp, instr);
|
continue;
|
||||||
strcat(tmp, d->d_name + strlen(base));
|
|
||||||
if (!stat(tmp, &s) && S_ISDIR(s.st_mode))
|
strcpy(tmp, instr);
|
||||||
strcat(tmp, "/");
|
strcat(tmp, d->d_name + strlen(base));
|
||||||
else
|
if (!stat(tmp, &s) && S_ISDIR(s.st_mode)) {
|
||||||
strcat(tmp, " ");
|
strcat(tmp, "/");
|
||||||
string_list_add_sorted(sl, tmp);
|
} else {
|
||||||
|
if (exec && !S_ISREG(s.st_mode))
|
||||||
|
continue;
|
||||||
|
strcat(tmp, " ");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
string_list_add_sorted(sl, tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
closedir(dir);
|
closedir(dir);
|
||||||
|
@ -316,9 +321,12 @@ int complete(char *instr, char **outstr)
|
||||||
instr = cmd_complete_lookup(&sl, t);
|
instr = cmd_complete_lookup(&sl, t);
|
||||||
if (!instr) {
|
if (!instr) {
|
||||||
instr = t;
|
instr = t;
|
||||||
if ((t = strrchr(t, ' '))) {
|
if (t && (t[0] == '/' || !strncmp(t, "./", 2))) {
|
||||||
|
file_complete(&sl, t, 1);
|
||||||
|
instr = t;
|
||||||
|
} else if ((t = strrchr(t, ' '))) {
|
||||||
t++;
|
t++;
|
||||||
file_complete(&sl, t);
|
file_complete(&sl, t, 0);
|
||||||
instr = t;
|
instr = t;
|
||||||
} else {
|
} else {
|
||||||
command_complete(&sl, instr);
|
command_complete(&sl, instr);
|
||||||
|
|
Loading…
Reference in New Issue