Well, your struggles are over. Just use "extensions" once upon startup of your computer, and you can tell a program to run based on its extension!
Usage
To use, simply run the program. It will replace the shell.run function with the new extension supporting program, while preserving the old function under the name of shell.runRaw.
The first time you run the program, it will additionally prompt you to create a file call extensions.cfg, which is a table of all available extensions, and the program which should run the file. Any number of custom extensions may be added, but note that files with custom extensions may behave oddly if you attempt to open them outside of ComputerCraft. Each entry in the table is simply a string value, or be the first key of a table value. If using a table value, you can also set the key noExt to true to trim the extension from the file name before passing it onto the program.
Additionally, the program will support two parameters to skip prompts (in case you are running it inside another program).
- The first one can be set to "create" to force creation of the extensions.cfg file and open the editing screen, "create-default" to create the default file without loading the editor, or "skip" to cancel if the file does not exist.
- Either of the two parameters can also be set to "load" to cancel running if the program has already run, or "reload" to rerun the program anyways (such as if you changed the extensions list and wish to reload it.)
- extensions.list - a table of all extensions, cached to the last time the extensions were loaded (meaning it will not reflect edits to extensions.cfg until reload, keeping it consistent with shell.run)
- extensions.program( string program ) - returns prog, file, noExt
- prog is the program used to run the program name given, or nil if no program is set for that extension. Useful to check if a program is actually a file, or to know how to read a file within another program.
- file is the name of the file, removing any args after the extension
- noExt is the input parameter without the extension on the file name, used internally by shell.run for the sake of certain programs which always add an extension (and expect none on the input args). Will be nil if the program does not set noExt to true
To install or update Extensions v2.1, simply use the following command to run the installer. It will automatically download the program and add it to your startup routine.
pastebin run QsNh3x2S
If you would download Extensions v2.1 manually (say you have a complicated startup routine, or a custom OS), simply use the following command to download just the program.
pastebin get 7Nq6R70n extensions