summaryrefslogtreecommitdiff
path: root/edit-readline.c
diff options
context:
space:
mode:
Diffstat (limited to 'edit-readline.c')
-rw-r--r--edit-readline.c16
1 files changed, 15 insertions, 1 deletions
diff --git a/edit-readline.c b/edit-readline.c
index 4a80044..bf7ff40 100644
--- a/edit-readline.c
+++ b/edit-readline.c
@@ -16,6 +16,19 @@ struct cookie {
char *buffer;
};
+/* can the name which we found in the first element of path be exec()d? */
+static bool is_command(List *path, char *name) {
+ char *full;
+ size_t len;
+
+ len = strlen(path->w) + strlen(name) + 2;
+ full = nalloc(len);
+ strcpy(full, path->w);
+ strcat(full, "/");
+ strcat(full, name);
+ return rc_access(full, FALSE);
+}
+
static char *compl_extcmd(const char *text, int state) {
static DIR *d;
static List *path;
@@ -32,7 +45,8 @@ static char *compl_extcmd(const char *text, int state) {
else {
struct dirent *e;
while ((e = readdir(d))) {
- if (strncmp(e->d_name, text, len) == 0)
+ if (strncmp(e->d_name, text, len) == 0 &&
+ is_command(path, e->d_name))
return strdup(e->d_name);
}
closedir(d);