Skip to content

Instantly share code, notes, and snippets.

@chapmanjacobd
Created April 25, 2022 21:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chapmanjacobd/42e554ce42c27abaf5967ae1306de1ec to your computer and use it in GitHub Desktop.
Save chapmanjacobd/42e554ce42c27abaf5967ae1306de1ec to your computer and use it in GitHub Desktop.
function funcdel --description 'Remove the current definition of all specified functions from session and file'
set -l options q/quiet h/help d/directory=
argparse -n funcdel $options -- $argv
or return
if set -q _flag_help
__fish_print_help funcdel
return 0
end
if set -q _flag_directory
set funcdir $_flag_directory
else
set funcdir $__fish_config_dir/functions
end
if not set -q argv[1]
printf (_ "%ls: Expected at least %d args, got only %d\n") funcdel 1 0 >&2
return 1
end
if not test -d $funcdir
printf (_ "%s: Configuration directory does not exist '%s'\n") funcdel $funcdir >&2
return 1
end
set -l retval 0
for funcname in $argv
set -l funcpath "$funcdir/$funcname.fish"
if not functions -q -- $funcname
printf (_ "%s: not defined as a function '%s'\n") funcdel $funcname >&2
set retval 1
else if not test -e $funcpath
printf (_ "%s: not a saved user function '%s'\n") funcdel $funcname >&2
set retval 2
else
functions --erase -- $funcname
rm $funcpath
and set -q _flag_quiet || printf (_ "%s: removed %s\n") funcdel $funcpath
end
end
return $retval
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment