How to remove functions from fishshell without directly deleting the function file?

I defined the hello function in fishshell:

 function hello echo Hello end 

And save it:

 funcsave hello 

If I want to delete it, I can delete the file ~/.config/fish/functions/hello.fish .

Is there any other way to do this? (e.g. built-in funcdel or funcrm )

+7
function fish
source share
4 answers

No, there is no embedded file to delete the file, but you can use:

 functions --erase hello 

or

 functions -e hello 

to erase the function definition from the current session.

see also

+8
source share

The above solution functions -e hello only deletes hello in the current session . Open another terminal and the function still exists.

To remove a function using a constant , I had to resort to deleting the file ~/.config/fish/functions/hello.fish directly. So far, I do not know of another method that deletes permanently.

+2
source share

I created another fish function for this

 function funcdel if test -e ~/.config/fish/functions/$argv[1].fish rm ~/.config/fish/functions/$argv[1].fish echo 'Deleted function ' $argv[1] else echo 'Not found function ' $argv[1] end end 
+1
source share

a more complete, self-defined (and quiet) self-implemented solution inspired by @Kanzee's answer (copy of the top file ~/.config/fish/functions/funcdel.fish ):

 function funcdel --description 'Deletes a fish function both permanently and from memory' set -l fun_name $argv[1] set -l fun_file ~/.config/fish/functions/$fun_name.fish # Delete the in-memory function, if it exists functions --erase $fun_name # Delete the function permanently, # if it exists as a file in the regular location if test -e $fun_file rm $fun_file end end 
0
source share

All Articles