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

Re: local unfunction



On Fri, Mar 30, 2018 at 6:11 PM, Ray Andrews <rayandrews@xxxxxxxxxxx> wrote:
> Is it possible to unfunction something just within another function?  I've
> tried:
>
> unset -fm ....
>
> ... but the functions remain dead after the calling function returns.  I can
> of course just resource them, but I'll bet the unset can be made local.

If it's okay to also cancel all other side effects, you can use a subshell,
function() hey {
  normal stuff here
  (
     unfunction foo
     foo
     a=5 # this will also disappear after the )
  )
}

-- 
Mikael Magnusson



Messages sorted by: Reverse Date, Date, Thread, Author