You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
warn if exiting fish with a unsaved but edited function #3701
I'm ambivalent about this proposal. Personally, I only use funced when I expressly want to make a transient change. If I want the change to be permanent I edit the underlying file and just let it be reloaded via the autoload mechanism. Rather than warn at exit time it would be simpler and safer, in my opinion, to modify funced to issue the warning after the user exits their editor. It would be best to write the warning only if the function was initially autoloaded but that will require implementing issue #3295.
@ridiculousfish but it opens a temporary file, I mean if a file exists for the function, it automatically opens that file in $EDITOR or if it doesn't, then it creates that file and opens that in $EDITOR. So no temp files if you set an option.
Either is fine with me, I'll just alias it if we go with an option. However, I think most people would prefer that the behaviour I described above becomes the default behaviour and the other is hidden behind an option. I don't really edit functions I need temporarily and it's not like keeping them stored will take up a lot of resources or slow down the shell startup time.
I don't think there is an overwhelming argument for either the current funced behavior to not automatically save the edit or the proposed behavior to do so. I think the tie-breaker is that changing existing default behavior should be avoided. So we should instead introduce something like a --perm / -p or --save / -s option pair to mean the edit should be persisted to the file system. And, as I said earlier, if that option isn't specified then display a reminder that the user may want to run funcsave to avoid losing their edit.
Also, I feel like @nhooyr is missing the main reason for the current behavior. It makes it easy to test a change without worrying about accidentally breaking the version that is stored in the file system. That is, I can use funced to easily add some diagnostic printf statements or explore "what if" questions without having to first save a copy of the autoloaded script (or have it under version control). If I'm happy with the change I can then run funcsave to persist it to disk. So while I wholeheartedly agree that fish should remind the user that they will lose those changes unless they use one of the aforementioned solutions I don't want those edits to be persisted to an autoloaded script by default.
Closing as a duplicate of issue #391. This issue discusses an aspect of the problem that was not previously discussed in #391 but it is essentially the same issue.
Activity
krader1961 commentedon Jan 6, 2017
I'm ambivalent about this proposal. Personally, I only use
funcedwhen I expressly want to make a transient change. If I want the change to be permanent I edit the underlying file and just let it be reloaded via the autoload mechanism. Rather than warn at exit time it would be simpler and safer, in my opinion, to modifyfuncedto issue the warning after the user exits their editor. It would be best to write the warning only if the function was initially autoloaded but that will require implementing issue #3295.ridiculousfish commentedon Jan 7, 2017
How about an option to
funcedlike--savewhich will runfuncsaveif the editor succeeds?krader1961 commentedon Jan 8, 2017
Adding a
-s/--saveoption is okay by me. However, I think a reminder message if the user didn't specify that option is still a good idea.floam commentedon Jan 8, 2017
I agree. I know I lost a number of functions as a new fish user that could have been rescued with a helpful reminder.
nhooyr commentedon Jan 8, 2017
@ridiculousfish how about an option to just straight up open the file in the editor?
ridiculousfish commentedon Jan 8, 2017
@nhooyr
funcedprefers to use$EDITORif set, is that what you mean?nhooyr commentedon Jan 8, 2017
@ridiculousfish but it opens a temporary file, I mean if a file exists for the function, it automatically opens that file in
$EDITORor if it doesn't, then it creates that file and opens that in$EDITOR. So no temp files if you set an option.krader1961 commentedon Jan 8, 2017
Do you propose to do that only if a specific option (e.g., the proposed
--saveoption) is used or make that the default behavior?nhooyr commentedon Jan 8, 2017
Either is fine with me, I'll just alias it if we go with an option. However, I think most people would prefer that the behaviour I described above becomes the default behaviour and the other is hidden behind an option. I don't really edit functions I need temporarily and it's not like keeping them stored will take up a lot of resources or slow down the shell startup time.
krader1961 commentedon Jan 9, 2017
I don't think there is an overwhelming argument for either the current
funcedbehavior to not automatically save the edit or the proposed behavior to do so. I think the tie-breaker is that changing existing default behavior should be avoided. So we should instead introduce something like a--perm/-por--save/-soption pair to mean the edit should be persisted to the file system. And, as I said earlier, if that option isn't specified then display a reminder that the user may want to runfuncsaveto avoid losing their edit.Also, I feel like @nhooyr is missing the main reason for the current behavior. It makes it easy to test a change without worrying about accidentally breaking the version that is stored in the file system. That is, I can use
funcedto easily add some diagnosticprintfstatements or explore "what if" questions without having to first save a copy of the autoloaded script (or have it under version control). If I'm happy with the change I can then runfuncsaveto persist it to disk. So while I wholeheartedly agree that fish should remind the user that they will lose those changes unless they use one of the aforementioned solutions I don't want those edits to be persisted to an autoloaded script by default.krader1961 commentedon Jan 10, 2017
Closing as a duplicate of issue #391. This issue discusses an aspect of the problem that was not previously discussed in #391 but it is essentially the same issue.