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

Re: preexec hook: possible enhancement?



On Wed, Sep 05, 2007 at 08:05:38PM +0100, Peter Stephenson wrote:
> Bart Schaefer wrote:
> > 
> > The TRAPDEBUG function is called at these points in the execution,
> > if you "setopt DEBUG_BEFORE_CMD".  However, I don't remember offhand
> > whether it's possible to access the command text that is about to be
> > executed.  The documentation for TRAPDEBUG is pretty sparse.
> > 
> > (Also DEBUG_BEFORE_CMD requires a very recent zsh version.)
> 
> I doubt if there's much joy there... debug traps are called before/after
> every command, including in precmd and preexec, so probably far too
> often.  (They're for debugging, right?)  The only argument to a
> TRAPDEBUG function is the signal number, which is meaningless in this
> case anyway.  The older stuff like this ksh import doesn't tend to be
> tightly enough defined to be useful interactively.

Yeah, that's what I gathered.  Since there doesn't seem to be a way to
get the text of the currently executing command from the debug trap,
nor to even tell if the currently executing was entered interactively,
I don't see any reasonable way to proceed down that road.
 
> The idea of a hook between pipelines is actually rather different from
> preexec and precmd; those get run around the time the shell fetches the
> line for editing, rather than in the middle of execution.  Running
> something after every pipeline would have to dig its mitts into into the
> execution tree, which is why Bart suggested debug traps.

I had a feeling it wouldn't be easy, but maintained a bit of hope that
somewhere along the line there was a function being called that was
both called for every command in an interactive pipeline and knew the
full text of the command it was being called for.  zsh's source is
still a bit scary for me, so I figured I should ask.
 
> It doesn't look like there's a clean way to do this.

Thanks for the input PWS.  :)

~Matt



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