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

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



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.

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.




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