help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: Roman Neuhauser <neuhauser@sigpipe.cz>
Cc: Zsh Users <zsh-users@zsh.org>
Subject: Re: chpwd, precmd hooks have "zsh" in $0
Date: Mon, 9 Aug 2021 14:26:58 -0700	[thread overview]
Message-ID: <CAH+w=7ZjVYzE6T+9Ditnzx4EFFAy0jMzsj9sD8gDBkJW97Mjow@mail.gmail.com> (raw)
In-Reply-To: <YRGM5st2N0tfvPMQ@isis.sigpipe.cz>

On Mon, Aug 9, 2021 at 1:16 PM Roman Neuhauser <neuhauser@sigpipe.cz> wrote:
> as the subject says, at least the chpwd and precmd hooks
> have the shell's argv[0] in $0.

This is because (most) hook functions are called with an empty (NULL)
argument list, as opposed to e.g. all commands (external, builtin, or
function) run from a command line, which have a non-empty argument
list starting with the command name itself.

In the particular case of preexec, the argument list is empty any time
history is not active, which is the case when loading a script with
"source" or "." builtins.  If you actually try it from the interactive
command line, you'll see that $0 is "preexec" in the call to every
function in the preexec_functions list.

I'm not sure what the desired behavior is here.  callhookfunc() could
dummy up a LinkNode any time its lnklst argument is empty, and then
all the hooks would behave in the manner preexec behaves when history
is enabled; or doshfunc() could do the same, in which case every
hook-array function would have its own name in $0; or neither of the
above is appropriate and we should document the current behavior.

  reply	other threads:[~2021-08-09 21:28 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-09 20:15 Roman Neuhauser
2021-08-09 21:26 ` Bart Schaefer [this message]
2021-08-10 11:33   ` Roman Neuhauser
2021-08-10 17:31     ` Bart Schaefer
2021-08-12  4:40       ` Roman Neuhauser
2021-08-15 21:10         ` 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:

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

  git send-email \
    --in-reply-to='CAH+w=7ZjVYzE6T+9Ditnzx4EFFAy0jMzsj9sD8gDBkJW97Mjow@mail.gmail.com' \
    --to=schaefer@brasslantern.com \
    --cc=neuhauser@sigpipe.cz \
    --cc=zsh-users@zsh.org \


* 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


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).