summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>2012-04-19 13:02:20 +0800
committerJean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>2012-04-30 20:37:40 +0800
commit9492976bc88a9fe4633202681fcdc24ce1dab636 (patch)
treec4baae97c5c43687f0c94c616a24d3abbc492b46
parent7e3a16ef14ec2a83853bdcf631b28939f01f0c18 (diff)
downloadbarebox-9492976bc88a9fe4633202681fcdc24ce1dab636.tar.gz
barebox-9492976bc88a9fe4633202681fcdc24ce1dab636.tar.xz
complete: add executable file support
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
-rw-r--r--common/complete.c30
1 files changed, 19 insertions, 11 deletions
diff --git a/common/complete.c b/common/complete.c
index 45c6908b58..0b03d7ce9a 100644
--- a/common/complete.c
+++ b/common/complete.c
@@ -26,7 +26,7 @@
#include <command.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);
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, ".."))
continue;
- if (!strncmp(base, d->d_name, strlen(base))) {
- strcpy(tmp, instr);
- strcat(tmp, d->d_name + strlen(base));
- if (!stat(tmp, &s) && S_ISDIR(s.st_mode))
- strcat(tmp, "/");
- else
- strcat(tmp, " ");
- string_list_add_sorted(sl, tmp);
+ if (strncmp(base, d->d_name, strlen(base)))
+ continue;
+
+ strcpy(tmp, instr);
+ strcat(tmp, d->d_name + strlen(base));
+ if (!stat(tmp, &s) && S_ISDIR(s.st_mode)) {
+ strcat(tmp, "/");
+ } else {
+ if (exec && !S_ISREG(s.st_mode))
+ continue;
+ strcat(tmp, " ");
}
+
+ string_list_add_sorted(sl, tmp);
}
closedir(dir);
@@ -316,9 +321,12 @@ int complete(char *instr, char **outstr)
instr = cmd_complete_lookup(&sl, t);
if (!instr) {
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++;
- file_complete(&sl, t);
+ file_complete(&sl, t, 0);
instr = t;
} else {
command_complete(&sl, instr);