Closed fatboychummy closed 3 weeks ago
Thanks for the PR! While I understand the motivation, I'm afraid I'm not going to merge this, for a couple of reasons:
shell.setAlias
to override the default shell
and lua
programs, but if you disable mbs (or a specific module), those aliases should no longer apply.I'm definitely open to doing a better job of documenting startup files. There was some work done on this in #1069, but that's stalled. I'm definitely open to someone else having another look at it.
A common problem with using settings definitions, shell aliases, and completions, is that they do not persist across a computer restart, unless you custom-build your program to write a file to something like
/startup/99_definitions.lua
. This works, but is (in my opinion) not very ideal, nor intuitive -- most people don't even realize you can make a startup folder! Thus, I decided to draft up this PR.With this, users can now add all of this information in their installer program and have it registered only once, but persist forever. It will also still work if the definitions are placed in the main program itself (as most people currently do things). However, the user won't have to run the program without arguments (or register a startup file) in order to get completions or settings definitions. Or at the very least, they only have to do it once, instead of once per startup.
Contents
This PR adds/modifies the following methods:
Settings
Additions
settings.saveDefinitions
: Saves the current settings definitions to disk. Saves to/.cc/settings.def
by default.settings.loadDefinitions
: Loads the current settings definitions from disk.Alterations
settings.save
/settings.load
: The new default storage location is/.cc/settings
Shell
Additions
shell.clearCompletionFunction
: Deletes a record of a completion function.shell.loadCompletionFunctions
: Loads all completion functions from disk.shell.saveAliases
: (NYI) -- Saves all current aliases to disk. Contemplating adding this since we won't be able to filter what actually saves to the disk easily (see the alterations sectionshell.setAlias
for more).shell.loadAliases
: Loads all aliases from disk.Alterations
shell.setCompletionFunction
: Now alternatively accepts aload
able string as its second argument.cc.shell.completion
library is injected into theload
environment.setCompletionFunction
with a function instead of a string will not save the function, it only saves if called with a string.shell.setAlias
: Added a third optional argument,dont_save
shell.setAlias
: Now saves aliases as they are created./.cc/aliases/<program name>
. Each alias file contains only a string for what the alias should refer to.BIOS
Additions
Alterations
/.settings
to/.cc/settings
and/.cc/settings.def
/.settings
.Startup
Additions
Alterations
shell.setAlias
calls now pass the new thirdtrue
parameter so they do not get saved to disk..cc
Folder StructureConsiderations
As outlined above, the settings are now stored by default in
/.cc/settings
(and/.cc/settings.def
). This could cause some backwards compatibility issues if a program manually alters/.settings
assuming thatsettings.save()
will store the data there.Edit: There are a few more edge cases that were discussed in Discord.
.settings
tosettings.save
instead of relying on the default: Upon restart, the setting will no longer be set, as.settings
is no longer the default..save()
s without an argument, then.load(".settings")
s, this will also fail..settings
, but theset
program would now default to storing in.cc/settings
Honestly, I will probably revert this change, but would like more feedback before I do so!
This is very much a draft PR, I need to write tests still as well as some general cleanup (i.e: variable names, need to use
fs.combine
in some locations, etc.). I wanted to get feedback on this before I went ahead on that step however. Thoughts on this? Concerns?