From 86af63cd398f7b8ac3b98ffd110f1e90366ce90f Mon Sep 17 00:00:00 2001 From: Kurtis Rader Date: Thu, 13 Jul 2017 13:35:26 -0700 Subject: [PATCH] update `funcsave` to use `argparse` --- share/functions/funcsave.fish | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/share/functions/funcsave.fish b/share/functions/funcsave.fish index cbd186efe..a52e1a3fe 100644 --- a/share/functions/funcsave.fish +++ b/share/functions/funcsave.fish @@ -1,20 +1,13 @@ - 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 - __fish_print_help funcsave - return 0 - end - else - printf (_ "%s: Expected function name\n") funcsave + if set -q _flag_help __fish_print_help funcsave - return 1 + return 0 end - set -l res 0 - set -l configdir ~/.config if set -q XDG_CONFIG_HOME set configdir $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