Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Best way to test for zsh features?
- X-seq: zsh-users 14609
- From: Peter Stephenson <pws@xxxxxxx>
- To: zsh-users@xxxxxxx
- Subject: Re: Best way to test for zsh features?
- Date: Wed, 25 Nov 2009 17:00:32 +0000
- In-reply-to: <4B0D5E30.7010505@xxxxxxxxxxxx>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <4B0D5E30.7010505@xxxxxxxxxxxx>
john_oshea@xxxxxxxxxxxx wrote:
> What's the best/cleanest/most "correct" way of checking for zsh features
> in an .zshrc? I've started to use vcs_info as part of my prompt, which
> works wonderfully in zsh's new enough to have that available, but gives
> me "function definition file not found" on machines with older zsh
> installations (that I'm unable to upgrade).
If the feature you're testing for is a function, it's quite easy to
define a function to look for the corresponding file.
function_exists () {
local -a files
# This expands occurrences of $1 anywhere in $fpath,
# removing files that don't exist.
files=(${^fpath}/$1(N))
# Success if any files exist.
(( ${#files} ))
}
You can now use this in tests:
if function_exists vcs_info; then
...
fi
--
Peter Stephenson <pws@xxxxxxx> Software Engineer
Tel: +44 (0)1223 692070 Cambridge Silicon Radio Limited
Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, UK
Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom
Messages sorted by:
Reverse Date,
Date,
Thread,
Author