Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
A method to not leak unneeded functions
- X-seq: zsh-users 24316
- From: Sebastian Gniazdowski <sgniazdowski@xxxxxxxxx>
- To: Zsh Users <zsh-users@xxxxxxx>
- Subject: A method to not leak unneeded functions
- Date: Mon, 30 Sep 2019 00:22:55 +0200
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=JEgKDKS7sKxkixpPGWXKWl7Yt0reLckf1vSxvRv0ufQ=; b=ocXapbJOemIV2PBZ0xzKbNrG5b1/t/bjA/rSVEqZm/J9UbC3eV95l69T9auBTfEO4D r5r+UQe3HKUOWHzupFAq3GXlzLnpPskH3diZyJ4eNJxTTP5PXlrly/VsvtpmI7IX+SFt xhlPis4Wy54XyLiIzGOLDXrKw8v2/AEA8QeyuI1pqh2Rl3b9RbX60b4GMAiu4ddbT9JZ eyQQgXXkDXqUVZ4a67pbU9b3l0lD3QaxFYqyZqaeAi3sPiyCXJIf30ktS8+RdFxVczee 74s0OeTMlR23xFFD5u7IpZZ8hWtAgSSyParCnWL2N8Vn6rhHdxEnLt0FBbCRn6rqeqa0 ZM0g==
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- List-unsubscribe: <mailto:zsh-users-unsubscribe@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
Hello,
it's often the case when one declares sub-functions inside an autoload
function. The function will leak into the shell and also get redefined
on the next run of the main function. Here's a method to prevent this
from happening:
local -a entry_funs
entry_funs=( ${(k)functions} )
trap "unset -f \"\${(k)functions[@]:#(${(j:|:)${(q@)entry_funs}})}\"
&>/dev/null" EXIT
trap "unset -f \"\${(k)functions[@]:#(${(j:|:)${(q@)entry_funs}})}\"
&>/dev/null; return 1" INT
It will unset any newly detected functions at the moment of leaving of
the main function.
--
Sebastian Gniazdowski
News: https://twitter.com/ZdharmaI
IRC: https://kiwiirc.com/client/chat.freenode.net:+6697/#zplugin
Blog: http://zdharma.org
Messages sorted by:
Reverse Date,
Date,
Thread,
Author