Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: A method to not leak unneeded functions
- X-seq: zsh-users 24317
- From: Sebastian Gniazdowski <sgniazdowski@xxxxxxxxx>
- To: Zsh Users <zsh-users@xxxxxxx>
- Subject: Re: A method to not leak unneeded functions
- Date: Mon, 30 Sep 2019 00:25:12 +0200
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=zHXoFfx3BnB3RLS2kDgss6ANt6DLB1xD4DjNozGDjac=; b=vJFD7yuxrQXAw/L78NKgORBKnigZrnKdBFYYVwzqW8MAxZzHah91RNUEXCKjOWX/I9 zgo3MPQOddSIfqq1mAU6Cd8ylfbqE3XdjilWfPIaKT0lra1T4dzwp3YfRz2HTa8kpbQs MdQ55VS6USZdwfqmd0b1Kc4P6CtBRx4j10N4DQgzUnER+ib9EOWydQMJPctbqav+xmCM WFZE4yoVNPKh41Ib8rCOvZe8791PIuHo6IUxVaw3byoPLqdPp2yiKkAxA0OGA4UoMqYs 18eLhruNsJUjVycVTDmFO0rXIn60o8Lt7QiCUjZ28d2/MpzT151dhUH/ZBAZVDmwCLfO PrcQ==
- In-reply-to: <CAKc7PVBiatCfaG5xupix8d8+VH_ScZJRRRJemUuND12Zk0TJuw@mail.gmail.com>
- 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
- References: <CAKc7PVBiatCfaG5xupix8d8+VH_ScZJRRRJemUuND12Zk0TJuw@mail.gmail.com>
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