diff options
| -rw-r--r-- | edit-readline.c | 16 | ||||
| -rw-r--r-- | rc.h | 5 | ||||
| -rw-r--r-- | which.c | 2 |
3 files changed, 20 insertions, 3 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); @@ -180,7 +180,6 @@ extern int lineno; /* builtins.c */ extern builtin_t *isbuiltin(char *); extern void b_exec(char **), funcall(char **), b_dot(char **), b_builtin(char **); -extern char *which(char *, bool); extern char *compl_builtin(const char *, int); /* except.c */ @@ -398,3 +397,7 @@ extern bool forked; /* walk.c */ extern bool walk(Node *, bool); extern bool cond; + +/* which.c */ +extern bool rc_access(char *, bool); +extern char *which(char *, bool); @@ -47,7 +47,7 @@ static int ingidset(gid_t g) { Returns a bool instead of this -1 nonsense. */ -static bool rc_access(char *path, bool verbose) { +bool rc_access(char *path, bool verbose) { struct stat st; int mask; if (stat(path, &st) != 0) { |