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

Re: Hooks



On Nov 7,  7:12am, Nikolai Weibull wrote:
}
} > This is even further away from the original subject, but I've often felt
} > that functions like preexec and chpwd are getting a bit overloaded and
} > are unnecessarily hard to maintain automatically.  It would be easy to
} > add an array which could contain names of functions to be executed,
} > similar to Emacs hooks.
} [...]
} > However, I'm not sure if it's really needed.
} 
} Yes, please do add.

Having previously implemented a shell-like language in which there was
such a set of hooks, I'll point out that there really ought to be a
well-defined semantics rather than simply executing every one of an
array of functions.  (I suppose that can *be* the defined semantics,
but it's not all that useful a one.)

For example, if one of the functions causes an error condition (the
sort of thing that would jump to the final clause of an "always" block)
is the whole chain aborted, or only the one function?

Related but more subtle, if a function returns a non-zero status,
should that affect the rest of the functions in the array in any way?
Put another way, are there rules for cascading the hooks?

And what is the value of "$@" when these functions are called?  Does
is differ depending on which hook array they're in?  (The signatures
of preexec, precmd, and chpwd are quite different.)

I'd suggest that, at least as a first pass, rather than coded up in C,
this be implmented with a few functions distributed in Functions/Misc
and designed to be installed as preexec, precmd, and/or chpwd.



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