Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: 'whence' question



On Wed, 05 Nov 2014 20:43:30 -0800
Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
> On Nov 5,  6:00pm, Peter Stephenson wrote:
> } Subject: Re: 'whence' question
> }
> } On Wed, 05 Nov 2014 18:49:23 +0100
> } Oliver Kiddle <okiddle@xxxxxxxxxxx> wrote:
> } > Looking at the source, it seems that whence doesn't support both -a and
> } > -m together though it doesn't produce an error.
> } 
> } You're right: I think *that's* a bug.
> 
> Hmm.  This is more complicated than it at first appears.

Moved to zsh-workers.

Don't we want something like this?

diff --git a/Src/builtin.c b/Src/builtin.c
index 5b711ed..101c19a 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -3228,11 +3228,39 @@ 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)) {
+			    zputs(buf, stdout);
+			    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();
 	}

-- 
Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/



Messages sorted by: Reverse Date, Date, Thread, Author