update funcsave to use argparse

This commit is contained in:
Kurtis Rader 2017-07-13 13:35:26 -07:00
parent 6ecd0bcb32
commit 86af63cd39

View file

@ -1,19 +1,12 @@
function funcsave --description "Save the current definition of all specified functions to file"
set -l options 'h/help'
argparse -n funcsave --min-args=1 $options -- $argv
or return
if count $argv >/dev/null
switch $argv[1]
case -h --h --he --hel --help
if set -q _flag_help
__fish_print_help funcsave
return 0
end
else
printf (_ "%s: Expected function name\n") funcsave
__fish_print_help funcsave
return 1
end
set -l res 0
set -l configdir ~/.config
if set -q XDG_CONFIG_HOME
@ -29,11 +22,12 @@ function funcsave --description "Save the current definition of all specified fu
end
end
for i in $argv
if functions -q -- $i
functions -- $i >$configdir/fish/functions/$i.fish
set -l res 0
for funcname in $argv
if functions -q -- $funcname
functions -- $i >$configdir/fish/functions/$funcname
else
printf (_ "%s: Unknown function '%s'\n") funcsave $i
printf (_ "%s: Unknown function '%s'\n") funcsave $funcname
set res 1
end
end