Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Is the function $f defined and is not an autoload stub?
- X-seq: zsh-users 21677
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: zsh-users@xxxxxxx
- Subject: Re: Is the function $f defined and is not an autoload stub?
- Date: Thu, 16 Jun 2016 09:16:14 -0700
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20150623.gappssmtp.com; s=20150623; h=from:message-id:date:in-reply-to:comments:references:to:subject :mime-version; bh=+dsQjPi4JC3e7WShibqTKNxZ8sZOyQ+mRi7dm3nq4i8=; b=y8Cp646syXUOkOfiaQrn4wHkQVn5FYCuqLvIFracZvrMSoB6BCjSu6Aezy8JXzogDq xP71P/QTjcIzjinajesuVygiQfU5WeK3+nDiL8fodLz4aCoDwpJT+zyCI4jkPVR/l9HI boeppK/9lRtj1TG/7hIHlok5iSNfzYXMlNd2mO0O/LFlEnHJCtjUu5DtOwqpmXb4TEtB El6EPSZ+RDpPOFbRLUtKxffpb9XE5ZPNCxIV4dDH1e7b+oWR/MHCd1SzFai7GSAsdHHt EjK0Xi5uOIO3ByBNzvpubnDRK7BJNNb3zrfKoyEQFpac69lSyR065G9vlKD2qzeB0/SE mlYA==
- In-reply-to: <20160615232447.GA27645@tarsus.local2>
- 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: <20160615232447.GA27645@tarsus.local2>
On Jun 15, 11:24pm, Daniel Shahaf wrote:
}
} I'd like to test whether the shell function $f is available (callable).
I suppose for consistency "autoload xyz" should return false if the
function is already fully defined (though what to do in the case of
"autoload xyz pdq" where one is defined and the other is not is a
bit ambiguous even for the +X case). Right now "autoload xyz" never
returns nonzero that I can tell.
Addressing the question of how to do it *now*, I think I'd choose to
do the test in a subshell so that testing doesn't change the state
of the calling shell. If that's acceptable, then:
if [[ "$functions[$f]" != *"builtin autoload -X" ]] ||
( unfunction -- "$f" && autoload +X -- "$f" ); then
print "Hooray, $f is callable"
fi
I prefixed the "builtin ..." with a * just in case at some point in
the future we begin including the "# undefined" comment in the body
for $functions[$f] the same way we do for $(functions $f).
Messages sorted by:
Reverse Date,
Date,
Thread,
Author