* whence not behaving as expected with noaliases set
@ 2022-10-23 18:31 Stefan Schmidt
2022-11-21 1:45 ` Matthew Martin
0 siblings, 1 reply; 3+ messages in thread
From: Stefan Schmidt @ 2022-10-23 18:31 UTC (permalink / raw)
To: zsh-workers
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`).
$ zsh --version
zsh 5.9 (x86_64-apple-darwin18.7.0)
$ zsh
% whence curl
/usr/bin/curl
% /usr/bin/curl --version | head -n 1 | awk '{ print $2 }'
7.54.0
% alias curl=/usr/local/Cellar/curl/7.85.0/bin/curl
% whence curl
/usr/local/Cellar/curl/7.85.0/bin/curl
% curl --version | head -n 1 | awk '{ print $2 }'
7.85.0
% setopt noaliases
% curl --version | head -n 1 | awk '{ print $2 }'
7.54.0
% whence curl
/usr/local/Cellar/curl/7.85.0/bin/curl
% type curl
curl is an alias for /usr/local/Cellar/curl/7.85.0/bin/curl
% where curl
curl: aliased to /usr/local/Cellar/curl/7.85.0/bin/curl
/usr/bin/curl
% which curl
curl: aliased to /usr/local/Cellar/curl/7.85.0/bin/curl
Am I misinterpreting or misunderstanding something here or is there in fact a contradiction between the documentation and the implementation?
If there is a contradiction, what would be the recommend way to resolve it?
Cheers,
Stefan
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: whence not behaving as expected with noaliases set
2022-10-23 18:31 whence not behaving as expected with noaliases set Stefan Schmidt
@ 2022-11-21 1:45 ` Matthew Martin
2022-11-21 5:14 ` Bart Schaefer
0 siblings, 1 reply; 3+ messages in thread
From: Matthew Martin @ 2022-11-21 1:45 UTC (permalink / raw)
To: Stefan Schmidt; +Cc: zsh-workers
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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: whence not behaving as expected with noaliases set
2022-11-21 1:45 ` Matthew Martin
@ 2022-11-21 5:14 ` Bart Schaefer
0 siblings, 0 replies; 3+ messages in thread
From: Bart Schaefer @ 2022-11-21 5:14 UTC (permalink / raw)
To: Stefan Schmidt, zsh-workers
On Sun, Nov 20, 2022 at 5:46 PM Matthew Martin <phy1729@gmail.com> wrote:
>
> On Sun, Oct 23, 2022 at 08:31:58PM +0200, Stefan Schmidt wrote:
> >
> > 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.
I'm not sure there was intended to be an implication that "whence"
would pay attention to noaliases. If used inside an "autoload -U"
function, for example, it's also going to report the "wrong" thing for
any command names used in that function, regardless of the global
setopt.
If we apply this change, I wonder if we should also extend the -a
option to continue to list aliases despite its current description of
"throughout the command path". It already lists builtins as well as
$path locations.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-11-21 5:15 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-23 18:31 whence not behaving as expected with noaliases set Stefan Schmidt
2022-11-21 1:45 ` Matthew Martin
2022-11-21 5:14 ` Bart Schaefer
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).