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

Re: Best way to test for zsh features?

Peter Stephenson wrote:
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.
    # Success if any files exist.
    (( ${#files} ))

You can now use this in tests:

  if function_exists vcs_info; then

Wonderful - thanks very much for that  :-)

John O'Shea
Wordbank Limited
33 Charlotte Street, London W1T 1RR
Direct line: +44 (0) 20 7903 8829
Fax: +44 (0) 20 7903 8888

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