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.
This commit is contained in:
Mahmoud Al-Qudsi 2020-03-20 10:03:05 -05:00
parent 75ae172ba2
commit 7f402cdae7

View File

@ -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