Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: chpwd, precmd hooks have "zsh" in $0



# schaefer@xxxxxxxxxxxxxxxx / 2021-08-10 10:31:00 -0700:
> On Tue, Aug 10, 2021 at 4:33 AM Roman Neuhauser <neuhauser@xxxxxxxxxx> wrote:
> > 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.

sorry, i didn't think much about the wording, and didn't mean to be offencisve.
if you (someone) can finish it i'll be grateful.
 
> > > 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).

yes, but there's other ways to let a function know it's being called as
part of a particular hook array.  there's only one reasonable way
of letting a function know the name it was called with.

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

use the correct name for a function defined with multiple names.
 
> Anyway, having output redirections on function definitions is another
> thing that was added quite late in the long history of the shell --

i know, it was me who asked for it back then.

  Date: Thu, 24 Jul 2014 14:23:31 +0200
  From: Roman Neuhauser <neuhauser@xxxxxxxxxx>
  To: zsh-users@xxxxxxx
  Subject: io-redirect in function definitions

> originally, the redirect would have been connected to the "function"
> command itself -- so there may be circumstances where you have to
> write
> 
>   function a b { { ... } > ab.log }
> 
> to be sure of getting what you meant there.  PWS may have more to say about it.

sure, a workaround exists and it's just a pair of braces and
an indentation level away.  my bitching here isn't motivated by
difficulty to achieve the effect with existing means.  i want the
shell to be simpler, conceptually smaller by having one kind of
functions: those that have their name in $0 and which don't forget
redirections defined after their body.

requests for changes "just" for the sake of some principles may be
annoying so i'll add that this conversation exists because i wanted
to use a single function in several hooks and modify its behavior
based on the hook name:

function generic-hook
{
  local hooks=${1}_functions
  work with ${(P)hooks}
}

-- 
roman




Messages sorted by: Reverse Date, Date, Thread, Author