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

A method to not leak unneeded functions



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