Persistence of shell aliases/completions, settings definitions. #2005
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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?