Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I had a function inside .zshrc that I removed.

Now, when I try to source it, it indeed sources it, but doesn't remove the function that once was inside .zshrc from memory.

Is there a way to remove the function (now I believe in memory, in zsh namespace or something like that) without restarting my machine?

share|improve this question
1  
You don't need to restart your machine, obviously. exec zsh will get you a fresh shell in the same terminal, directory, environment, etc. –  Gilles Mar 8 '11 at 18:55

1 Answer 1

up vote 4 down vote accepted

In zsh, you can remove a function with unhash -f functionname or unfunction functionname.

That doesn't automatically clear functions you've removed from a given startup file, though, because of course the shell doesn't remember where it got it from in the first place and attribute any special meaning to re-sourcing the same file. So you'll have to know what you want to forget.

Since you mention .bashrc in the subject: the bash equivalent is unset -f functioname

share|improve this answer
    
If a function is binded to a key (bindkey command), is it possible to remove it as well? –  Somebody still uses you MS-DOS Mar 7 '11 at 21:34
    
@Somebody still uses you MS-DOS — if you remove the function without removing the key binding, you'll get No such shell function `function' when you press the key. But perhaps what you want to do is start your key definitions in your dotfile with bindkey -d, to reset them to their default state each time before setting up custom things. –  mattdm Mar 7 '11 at 21:54

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.