78

I'm currently building a program which adds to the current user's shell depending on the project he's working on, by defining per-project aliases and functions. These aliases and functions may and will certainly have the same name like for instance cdproj, which would cd to the project's root.

I would like to remove previously defined aliases and functions when changing project (before (re)defining aliases and functions for the other project. I know I can remove an alias with unalias in both bash and zsh, but how would I do the same for a function?

greg0ire
  • 22,714
  • 16
  • 72
  • 101
  • Interesting thing is that this is not totally a duplicate. The question is not about bash only. There is a reference to `zsh` too. – Victor Yarema Nov 06 '17 at 22:25
  • @VictorYarema More interesting, Zsh tag was recently added to that question (direct edit by high-reputation users), making this a valid duplicate. – Franklin Yu Jan 18 '20 at 07:11
  • This happend to `grep`. I couldn't decide whether it was funny or not. I couldn't grep for possible locations. – Sridhar Sarnobat Apr 29 '22 at 02:16

2 Answers2

114
unset -f my_function

will remove (or unset) the function my_function

ennuikiller
  • 46,381
  • 14
  • 112
  • 137
29

unfunction my_function in zsh

Perhaps, I'm a bit late in this good old '15, but this feature persists.

theoden8
  • 773
  • 7
  • 16