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

Re: "Fallback" alias/function in zsh



On Dec 8, 10:04pm, Paul Moore wrote:
> Subject: "Fallback" alias/function in zsh
>
> Is it possible to define a function which gets used whenever zsh's
> normal alias/function/builtin/path lookup fails?

In 3.1.5, there's the preexec() function, in which you could do something
like this:

  function preexec() {
    command=("$@")
  }
  function precmd() {
    (($?)) && CMD /C "$command[@]"
  }

That means, before executing the command, save it in $command; then, after
executing it (and just before printing the prompt) if the exit status was
nonzero, attempt to execute the command with CMD /C.

This will do unusual things when you execute compound commands (separated
with ; && || etc.) and won't work for backgrounded commands (&) but should
do what you want for simple commands typed at the prompt.

Of course, 3.1.5 isn't ported to Windows yet ...



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