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: Tue, 10 Aug 2021 10:31:00 -0700	[thread overview]
Message-ID: <CAH+w=7bQN-uuaW-hthX0Wi5J1mmsyB4AsWN0JP75vG0z_zwmRw@mail.gmail.com> (raw)
In-Reply-To: <YRJkDTl9cMxzn4Gd@isis.sigpipe.cz>

On Tue, Aug 10, 2021 at 4:33 AM Roman Neuhauser <neuhauser@sigpipe.cz> wrote:
> how did this happen?

I return to what I told Marlon the other day:

The answer to "why doesn't feature A take advantage of feature B" is
often "because A was developed long before B".

The code for calling the hook functions has been around since long
before the FUNCTION_ARGZERO option was added, and nobody thought to
update all the entry points.  When the code for the arrays of hooks
was further added, it just passed through what the base function was
already getting.

> come to think of it, if so taxing to implement fully, why is it built
> into the shell in the first place?

It's not "taxing", it's just forgotten.  It was built into the C code
so that people's existing hook functions (precmd, preexec, chpwd,
etc.) wouldn't have to be changed/overwritten to "know about" the new
special arrays, and so that e.g. module writers could plug into those
arrays without fear that a user could change the calling protocol.

> and is it too late to reverse the
> course, gut the half-assed implementation with one written using shell
> functions?

There's no need to be offensive about it, but yes, it's too late.  The
implementation actually has all the interfaces it needs to populate
FUNCTION_ARGZERO properly, it was just never noticed/found necessary
to do so.

> > 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?

Theoretically, a function might prefer to know that it was being
called as a consequence of being found in a given hook list, vs. being
called directly.  That might argue for (1).  However, since the
current situation is (3), the only instance where that could exist in
practice is for the preexec hooks, so we're probably safe choosing

I will note, to avoid yet again having an "A forgot B" situation, that
Zftp module hooks also behave like (3) and would begin to have their
own name in $0 if we change doshfunc().

>     function a b { ... } > ab.log
>     precmd_functions=(a)
>     preexec_functions=(b)
> 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. :(

I'm not sure what "the first" is here?

Anyway, having output redirections on function definitions is another
thing that was added quite late in the long history of the shell --
originally, the redirect would have been connected to the "function"
command itself -- so there may be circumstances where you have to

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

to be sure of getting what you meant there.  PWS may have more to say about it.

  reply	other threads:[~2021-08-10 17:31 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
2021-08-10 17:31     ` Bart Schaefer [this message]
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=7bQN-uuaW-hthX0Wi5J1mmsyB4AsWN0JP75vG0z_zwmRw@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).