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

Re: "Fallback" alias/function in zsh



On Dec 9,  1:19am, Phil Pennock wrote:
} Subject: Re: "Fallback" alias/function in zsh
}
} Typing away merrily, Bart Schaefer produced the immortal words:
} > 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 seems dangerous.  The problem looks to be 'if path lookup fails'
} not 'if path lookup fails or program returns non-zero'; could be fun to
} run a grep(1) port and have it run twice if no matches were found ...

Easily enough adjusted:

  function precmd() {
    (($?)) && { whence "$command[1]" >& /dev/null || CMD /C "$command[@]" }
  }

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com



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