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

# schaefer@brasslantern.com / 2021-08-09 14:26:58 -0700:
> 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.

how did this happen?  was it the shortest patch that wouldn't crash
the shell?  you give no hints of benefits this should have for users,
and i can't think of any either.

come to think of it, if so taxing to implement fully, why is it built
into the shell in the first place?  and is it too late to reverse the
course, gut the half-assed implementation with one written using shell
functions?  so much in zsh is done that way, why is the loop over
foo_functions written in C?

> 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.
what are the downsides of (2) for users of the shell?  both (1) and (3)
result in loss of information and deviation from standard behavior,
and what is lost in behavior is gained in length of the manual.
(2) preserves information, gets rid of a special case, and nullifies
the need for more documentation.  that is, i'm assuming that functions
plugged into any hook behave as actual functions, IOW

    function a b { ... } > ab.log

calls the function with $0 == "a" in precmd, "b" in preexec,
and that their runtime output goes to ab.log.  hooks do neither
and TRAPNAL functions only the first. :(


  reply	other threads:[~2021-08-10 11:34 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
2021-08-10 11:33   ` Roman Neuhauser [this message]
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=YRJkDTl9cMxzn4Gd@isis.sigpipe.cz \
    --to=neuhauser@sigpipe.cz \
    --cc=schaefer@brasslantern.com \
    --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).