Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: A conditional test to see whether a function is loaded?
- X-seq: zsh-users 11541
- From: Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>
- To: zsh-users@xxxxxxxxxx
- Subject: Re: A conditional test to see whether a function is loaded?
- Date: Sat, 09 Jun 2007 20:44:31 +0100
- In-reply-to: Message from fREW <frioux@xxxxxxxxx> of "Sat, 09 Jun 2007 09:16:50 MDT." <fb3648c60706090816h5c5b6329o9bfc6af0baaa998a@xxxxxxxxxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
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