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

Re: A conditional test to see whether a function is loaded?



fREW wrote:
> On 6/9/07, William Scott <wgscott@xxxxxxxxxxxxxxxxxx> wrote:
> > Thanks!
> >
> > Frank Terbeck wrote:
> >
> > > zsh% [[ -n ${functions[promptinit]} ]] && echo yay || echo nay
> >
> 
> I have a similar question.  Is there a shorter, more zsh-y way to do:
> [[ -x `which aptitude` ]]

Basically the same answer; you need to look at the description of the
zsh/parameter module in the zshmodules manual page for this kind of
thing.  These are the same parameters the completion system uses:

[[ -x ${commands[aptitude]} ]] && echo yay || echo nay

> Obviously replace aptitude with any program.  I tried [[ -x =aptitude
> ]] but that gives error messages if it doesn't exist.

fn() {
   emulate -L zsh
   setopt nonomatch
   [[ -x =aptitude ]]
}

will fix that problem.  You can use a parameter expression; parameter
expansion occurs before =-expansion (unless you have the bad taste
to set SH_FILE_EXPANSION, but "emulate" takes care of that in this case):

fn() {
   emulate -L zsh
   setopt nonomatch
   [[ -x =$1 ]]
}

-- 
Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/



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