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

Re: More verbose && ?

On Jan 20,  6:34pm, Richard Hartmann wrote:
} I would definitely prefer an invisible and automagic way, ideally
} activated via an option.

I think you're unlikely to get your wish in exactly that form, but
if someone is feeling ambitious, here are some pointers:

Look in Src/exec.c for the comment

    /* Get the text associated with this command. */

The variable "text" assigned there is the closest approximation to
what you'd like reported.  By the time zsh gets around to executing a
command, it has been rearranged by the parser into bytecode sequences,
and without going through the same exercises that the XTRACE option
enables, the exact text can't be regenerated.  For example, in a math
expression like (( 0 )) the "text" is entirely gone and would have
to be reconstructed in execarith().  There are a lot of special
cases to cover.

In any case, that text would then need to be stashed somewhere from
whence it could later be retrieved and printed.  E.g., if it were
stored in the parameter $ZSH_LAST_CMD, then Richard could almost get
what he wants by using

TRAPZERR() { print -R "Error($?): $ZSH_LAST_CMD" }

I say "almost" because when one of the "branches" of the && list is
a shell function or other complex command, it' unclear to me what
the "last command" will end up being.

Aside to -workers:  Shouldn't ZSH_DEBUG_CMD be mentioned in the section
of the manual for "parameters set by the shell"?

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