zsh-users
 help / color / mirror / code / Atom feed
* A method to not leak unneeded functions
@ 2019-09-29 22:22 Sebastian Gniazdowski
  2019-09-29 22:25 ` Sebastian Gniazdowski
  0 siblings, 1 reply; 4+ messages in thread
From: Sebastian Gniazdowski @ 2019-09-29 22:22 UTC (permalink / raw)
  To: Zsh Users

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-10-03 23:26 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-29 22:22 A method to not leak unneeded functions Sebastian Gniazdowski
2019-09-29 22:25 ` Sebastian Gniazdowski
2019-10-03 23:18   ` Sebastian Gniazdowski
2019-10-03 23:25     ` Sebastian Gniazdowski

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).