From 7f402cdae732d6ab90ea12222b34f947fa859e7c Mon Sep 17 00:00:00 2001 From: Mahmoud Al-Qudsi Date: Fri, 20 Mar 2020 10:03:05 -0500 Subject: [PATCH] Make `funcsave` update the function <-> file mapping This makes `funced` after `funcsave` behave as expected rather than a potential source of data loss. Closes #6113. --- share/functions/funcsave.fish | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/share/functions/funcsave.fish b/share/functions/funcsave.fish index 20e60c06e..31863fc3d 100644 --- a/share/functions/funcsave.fish +++ b/share/functions/funcsave.fish @@ -22,6 +22,20 @@ function funcsave --description "Save the current definition of all specified fu for funcname in $argv if functions -q -- $funcname functions -- $funcname >$__fish_config_dir/functions/$funcname.fish + # https://github.com/fish-shell/fish-shell/issues/6113 + # Use the newly saved file as the source of the function, allowing + # a subsequent `funced` to modify the correct version of the file. + # + # Ideally this would be done in fish core and would simply update the + # function <-> file mapping, but as funcsave/funced are fish scripts, + # this is close enough. It's guaranteed to be free of side effects + # because `functions $funcname` returns only a function declaration + # without any initialization code, etc. you may find in a fish script. + functions -e $funcname + # `functions -e` is not enough on its own since it prevents future + # autoloading of a function by the same name, even from a different + # location. Possibly something to improve in the future? + source $__fish_config_dir/functions/$funcname.fish else printf (_ "%s: Unknown function '%s'\n") funcsave $funcname set retval 1