Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: chpwd, precmd hooks have "zsh" in $0
- X-seq: zsh-users 26888
- From: Roman Neuhauser <neuhauser@xxxxxxxxxx>
- To: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- Cc: Zsh Users <zsh-users@xxxxxxx>
- Subject: Re: chpwd, precmd hooks have "zsh" in $0
- Date: Tue, 10 Aug 2021 13:33:33 +0200
- Archived-at: <https://zsh.org/users/26888>
- In-reply-to: <CAH+w=7ZjVYzE6T+9Ditnzx4EFFAy0jMzsj9sD8gDBkJW97Mjow@mail.gmail.com>
- List-id: <zsh-users.zsh.org>
- References: <YRGM5st2N0tfvPMQ@isis.sigpipe.cz> <CAH+w=7ZjVYzE6T+9Ditnzx4EFFAy0jMzsj9sD8gDBkJW97Mjow@mail.gmail.com>
# schaefer@xxxxxxxxxxxxxxxx / 2021-08-09 14:26:58 -0700:
> On Mon, Aug 9, 2021 at 1:16 PM Roman Neuhauser <neuhauser@xxxxxxxxxx> 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
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. :(
--
roman
Messages sorted by:
Reverse Date,
Date,
Thread,
Author