zsh-workers
 help / color / mirror / code / Atom feed
From: Matthew Martin <phy1729@gmail.com>
To: Stefan Schmidt <Stefan.Schmidt@gmx.de>
Cc: zsh-workers@zsh.org
Subject: Re: whence not behaving as expected with noaliases set
Date: Sun, 20 Nov 2022 19:45:42 -0600	[thread overview]
Message-ID: <Y3rYRgGp+QQDqqKI@CptOrmolo.darkstar> (raw)
In-Reply-To: <trinity-79c2b1d1-c907-48b5-ba61-26c0c72b7b6f-1666549918615@3c-app-gmx-bap60>

On Sun, Oct 23, 2022 at 08:31:58PM +0200, Stefan Schmidt wrote:
> Hello!
> 
> The documentation on whence states:
> 
> > For each name, indicate how it would be interpreted if used as a command name.
> https://zsh.sourceforge.io/Doc/Release/Shell-Builtin-Commands.html
> 
> This works as expected if an alias is defined but if the `noaliases` option is set `whence` still returns the alias (same for `type`, `where` and `which`).

> Am I misinterpreting or misunderstanding something here or is there in fact a contradiction between the documentation and the implementation?

I think your interpretation is correct. This seems straight forward
enough to fix. Diff is mostly indentation changes.

diff --git a/Src/builtin.c b/Src/builtin.c
index a7b7755a7..2298b1559 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -3902,9 +3902,11 @@ bin_whence(char *nam, char **argv, Options ops, int func)
 		 * We're not using it, so search for ... */
 
 		/* aliases ... */
-		informed +=
-		scanmatchtable(aliastab, pprog, 1, 0, DISABLED,
-			       aliastab->printnode, printflags);
+		if (isset(ALIASESOPT)) {
+		    informed +=
+		    scanmatchtable(aliastab, pprog, 1, 0, DISABLED,
+		                   aliastab->printnode, printflags);
+		}
 
 		/* and reserved words ... */
 		informed +=
@@ -3944,21 +3946,23 @@ bin_whence(char *nam, char **argv, Options ops, int func)
 	if (!OPT_ISSET(ops,'p') && !allmatched) {
 	    char *suf;
 
-	    /* Look for alias */
-	    if ((hn = aliastab->getnode(aliastab, *argv))) {
-		aliastab->printnode(hn, aliasflags);
-		informed = 1;
-		if (!all)
-		    continue;
-	    }
-	    /* Look for suffix alias */
-	    if ((suf = strrchr(*argv, '.')) && suf[1] &&
-		suf > *argv && suf[-1] != Meta &&
-		(hn = sufaliastab->getnode(sufaliastab, suf+1))) {
-		sufaliastab->printnode(hn, printflags);
-		informed = 1;
-		if (!all)
-		    continue;
+	    if (isset(ALIASESOPT)) {
+		/* Look for alias */
+		if ((hn = aliastab->getnode(aliastab, *argv))) {
+		    aliastab->printnode(hn, aliasflags);
+		    informed = 1;
+		    if (!all)
+			continue;
+		}
+		/* Look for suffix alias */
+		if ((suf = strrchr(*argv, '.')) && suf[1] &&
+		    suf > *argv && suf[-1] != Meta &&
+		    (hn = sufaliastab->getnode(sufaliastab, suf+1))) {
+		    sufaliastab->printnode(hn, printflags);
+		    informed = 1;
+		    if (!all)
+			continue;
+		}
 	    }
 	    /* Look for reserved word */
 	    if ((hn = reswdtab->getnode(reswdtab, *argv))) {
diff --git a/Test/B13whence.ztst b/Test/B13whence.ztst
index 3b35835fe..658a9bcab 100644
--- a/Test/B13whence.ztst
+++ b/Test/B13whence.ztst
@@ -32,3 +32,13 @@
     whence -S flip || whence -S loop || whence -s flip || whence -s loop
   )
 1:whence deals with symlink loops gracefully
+
+  (
+    alias echo=print
+    whence echo
+    setopt noaliases
+    whence echo
+  )
+0:whence ignore aliases with NO_ALIASES set
+>print
+>echo


  reply	other threads:[~2022-11-21  1:46 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-23 18:31 Stefan Schmidt
2022-11-21  1:45 ` Matthew Martin [this message]
2022-11-21  5:14   ` Bart Schaefer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Y3rYRgGp+QQDqqKI@CptOrmolo.darkstar \
    --to=phy1729@gmail.com \
    --cc=Stefan.Schmidt@gmx.de \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).