zsh-users
 help / color / mirror / code / Atom feed
* trigger prexec function from a script
@ 2013-06-07  9:47 Eric Smith
  2013-06-07 10:16 ` Peter Stephenson
  0 siblings, 1 reply; 2+ messages in thread
From: Eric Smith @ 2013-06-07  9:47 UTC (permalink / raw)
  To: Zsh Users

Oh Zshellers,

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?

FWIW;
function preexec {
local cmd
local application
cmd=(${(Q)${(z)3}})
if [[ $cmd[1] == (*foo) ]]; then
    application=bar
fi
if [ $application ];then
    eval "function ${(q)cmd[1]} {
        unsetopt noglob
        $application $url${(q)cmd[1]}" '$*
          return
        unfunction' "${(q)cmd[1]}
    }"
setopt noglob
fi

-- 
Eric Smith


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: trigger prexec function from a script
  2013-06-07  9:47 trigger prexec function from a script Eric Smith
@ 2013-06-07 10:16 ` Peter Stephenson
  0 siblings, 0 replies; 2+ messages in thread
From: Peter Stephenson @ 2013-06-07 10:16 UTC (permalink / raw)
  To: Zsh Users

On Fri, 07 Jun 2013 11:47:11 +0200
Eric Smith <Eric.Smith@trustfood.org> 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


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2013-06-07 10:16 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-06-07  9:47 trigger prexec function from a script Eric Smith
2013-06-07 10:16 ` Peter Stephenson

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).