fork/fish-shell

git clone https://git.julia.blue/fork/fish-shell

Daniel Rainerprintf: remove all uses of length modifiers83af5c91b

master
1.3 KiB45 linesraw
1# localization: tier1
2function funcsave --description "Save the current definition of all specified functions to file"
3    set -l options q/quiet h/help d/directory=
4    argparse -n funcsave $options -- $argv
5    or return
6
7    if set -q _flag_help
8        __fish_print_help funcsave
9        return 0
10    end
11
12    set -l funcdir
13    if set -q _flag_directory
14        set funcdir $_flag_directory
15    else
16        set funcdir $__fish_config_dir/functions
17    end
18
19    if not set -q argv[1]
20        printf (_ "%s: Expected at least %d args, got only %d\n") funcsave 1 0 >&2
21        return 1
22    end
23
24    if not mkdir -p $funcdir
25        printf (_ "%s: Could not create configuration directory '%s'\n") funcsave $funcdir >&2
26        return 1
27    end
28
29    set -l retval 0
30    for funcname in $argv
31        set -l funcpath "$funcdir/$funcname.fish"
32        if functions -q -- $funcname
33            functions --no-details -- $funcname >$funcpath
34            and set -q _flag_quiet || printf (_ "%s: wrote %s\n") funcsave $funcpath
35        else if test -w $funcpath
36            command rm $funcpath
37            and set -q _flag_quiet || printf (_ "%s: removed %s\n") funcsave $funcpath
38        else
39            printf (_ "%s: Unknown function '%s'\n") funcsave $funcname >&2
40            set retval 1
41        end
42    end
43
44    return $retval
45end