diff --git a/doc_src/funced.txt b/doc_src/funced.txt index 720c082a0788..b8a7db530c84 100644 --- a/doc_src/funced.txt +++ b/doc_src/funced.txt @@ -16,3 +16,5 @@ If there is no function called `NAME` a new function will be created with the sp - `-e command` or `--editor command` Open the function body inside the text editor given by the command (for example, `-e vi`). The special command `fish` will use the built-in editor (same as specifying `-i`). - `-i` or `--interactive` Force opening the function body in the built-in editor even if `$VISUAL` or `$EDITOR` is defined. + +- `-s` or `--save` Automatically save the function after successfully editing it. diff --git a/share/functions/funced.fish b/share/functions/funced.fish index e8e05a72a84c..706e0ee16fb7 100644 --- a/share/functions/funced.fish +++ b/share/functions/funced.fish @@ -12,7 +12,7 @@ function __funced_md5 end function funced --description 'Edit function definition' - set -l options 'h/help' 'e/editor=' 'i/interactive' + set -l options 'h/help' 'e/editor=' 'i/interactive' 's/save' argparse -n funced --min-args=1 --max-args=1 $options -- $argv or return @@ -65,6 +65,9 @@ function funced --description 'Edit function definition' echo -n $cmd | fish_indent | read -lz cmd eval "$cmd" end + if set -q _flag_save + funcsave $funcname + end return 0 end @@ -115,6 +118,8 @@ function funced --description 'Edit function definition' continue end echo (_ "Cancelled function editing") + else if set -q _flag_save + funcsave $funcname end end break