Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Is the function $f defined and is not an autoload stub?
- X-seq: zsh-users 21671
- From: Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx>
- To: zsh-users@xxxxxxx
- Subject: Is the function $f defined and is not an autoload stub?
- Date: Wed, 15 Jun 2016 23:24:47 +0000
- 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
export f=add-zle-hook-widget
I'd like to test whether the shell function $f is available (callable).
The naive solution, (( ${+functions[$f]} )), is not specific: it always
returns 1 after after 'autoload $f', even if the function is not
actually available (= calling it will fail with "zsh: $f: function
definition file not found").
The next candidate, «if autoload +X $f 2>/dev/null», is not idempotent:
it returns 'false' if «autoload +X $f» had already been run.
I suppose I could do this:
.
if autoload +X -- $f 2>/dev/null;
[[ "${${(@f)"$(which -- $f)"}[2]}" != $'\t'$histchars[3]' undefined' ]];
then
fi
.
but I'm hoping there's a saner way....
Thanks,
Daniel
(before you ask: I'd rather not use is-at-least because feature checks
are better than version checks)
Messages sorted by:
Reverse Date,
Date,
Thread,
Author