mirror of
https://github.com/fish-shell/fish-shell.git
synced 2024-11-23 12:28:39 +08:00
9c327b19a6
New fish_indent does that too, so this will make any future reformatting diffs smaller. Done using either of: perl -pi -e 'undef $/; s/\n*$/\n/' share/**.fish kak -n -f '<a-/>\n*<ret>d' share/**.fish
39 lines
991 B
Fish
39 lines
991 B
Fish
function funcsave --description "Save the current definition of all specified functions to file"
|
|
set -l options h/help 'd/directory='
|
|
argparse -n funcsave $options -- $argv
|
|
or return
|
|
|
|
if set -q _flag_help
|
|
__fish_print_help funcsave
|
|
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") funcsave 1 0
|
|
return 1
|
|
end
|
|
|
|
if not mkdir -p $funcdir
|
|
printf (_ "%s: Could not create configuration directory '%s'\n") funcsave $funcdir
|
|
return 1
|
|
end
|
|
|
|
set -l retval 0
|
|
for funcname in $argv
|
|
if functions -q -- $funcname
|
|
functions -- $funcname >$funcdir/$funcname.fish
|
|
else
|
|
printf (_ "%s: Unknown function '%s'\n") funcsave $funcname
|
|
set retval 1
|
|
end
|
|
end
|
|
|
|
return $retval
|
|
end
|