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

Re: trigger prexec function from a script



On Fri, 07 Jun 2013 11:47:11 +0200
Eric Smith <Eric.Smith@xxxxxxxxxxxxx> wrote:
> I have a prexec function and this works fine when I put a
> filename on the prompt and press enter. How do I make the preexec
> fire when I deliver the command from script?

Unfortunately this is quite heavily tied to executing an interactive
command line, and I don't think turning on interactive mode for
executing the script is good enough either (though I haven't actually
tried).

You're best bet might be to use the DEBUG trap.  If you define the
function as TRAPDEBUG instead of preexec it'll get called before each
command.  The effect isn't quite the same, since it'll get called more
often than it would before a complete command line.  You can examine
what is about to be executed in $ZSH_DEBUG_CMD (see the documentation
for the trap builtin).

pws



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