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

Re: A method to not leak unneeded functions



PS. The block of code should be added at the beginning of the autoload
file, after possible emulate -L zsh, or at least after `setopt
localtraps' (which is being done by the emulate builtin). After this
the setup is complete and the functions will get automatically unset.

On Mon, 30 Sep 2019 at 00:22, Sebastian Gniazdowski
<sgniazdowski@xxxxxxxxx> wrote:
>
> 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



-- 
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