about summary refs log tree commit diff
path: root/Src/builtin.c
diff options
context:
space:
mode:
authorPeter Stephenson <p.w.stephenson@ntlworld.com>2014-11-08 20:49:07 +0000
committerPeter Stephenson <p.w.stephenson@ntlworld.com>2014-11-08 20:49:07 +0000
commit0ccbc3873f7023a717973e9fe2a4e94317b35ad4 (patch)
tree22ad68a58814f85bd77159343874e1c893fa762f /Src/builtin.c
parent63f3030aaa79261466558c9a32707b16aabbeacc (diff)
downloadzsh-0ccbc3873f7023a717973e9fe2a4e94317b35ad4.tar.gz
zsh-0ccbc3873f7023a717973e9fe2a4e94317b35ad4.tar.xz
zsh-0ccbc3873f7023a717973e9fe2a4e94317b35ad4.zip
Handle -a option to whence in combination with -m.
Diffstat (limited to 'Src/builtin.c')
-rw-r--r--Src/builtin.c46
1 files changed, 41 insertions, 5 deletions
diff --git a/Src/builtin.c b/Src/builtin.c
index 5b711edc0..dd22d0984 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -3228,11 +3228,47 @@ bin_whence(char *nam, char **argv, Options ops, int func)
 		scanmatchtable(builtintab, pprog, 1, 0, DISABLED,
 			       builtintab->printnode, printflags);
 	    }
-	    /* Done search for `internal' commands, if the -p option *
-	     * was not used.  Now search the path.                   */
-	    cmdnamtab->filltable(cmdnamtab);
-	    scanmatchtable(cmdnamtab, pprog, 1, 0, 0,
-			   cmdnamtab->printnode, printflags);
+	    if (all) {
+		char **pp, *buf, *fn;
+		DIR *od;
+
+		pushheap();
+		for (pp = path; *pp; pp++) {
+		    if (!**pp)
+			continue;
+		    od = opendir(*pp);
+		    if (!od)
+			continue;
+
+		    while ((fn = zreaddir(od, 0))) {
+			if (!pattry(pprog, fn))
+			    continue;
+
+			buf = zhtricat(*pp, "/", fn);
+
+			if (iscom(buf)) {
+			    if (wd) {
+				printf("%s: command\n", fn);
+			    } else {
+				if (v && !csh)
+				    zputs(fn, stdout), fputs(" is ", stdout);
+				zputs(buf, stdout);
+				if (OPT_ISSET(ops,'s'))
+				    print_if_link(buf);
+				fputc('\n', stdout);
+			    }
+			}
+		    }
+		    closedir(od);
+		}
+		popheap();
+	    } else {
+		/* Done search for `internal' commands, if the -p option *
+		 * was not used.  Now search the path.                   */
+		cmdnamtab->filltable(cmdnamtab);
+		scanmatchtable(cmdnamtab, pprog, 1, 0, 0,
+			       cmdnamtab->printnode, printflags);
+	    }
 
 	    unqueue_signals();
 	}