CC: Tweaked

CC: Tweaked

42M Downloads

Add hashbangs

crabdancing opened this issue ยท 2 comments

commented

Or in this case...hyphen bangs. A special optional line at the top of a text file to tell CraftOS to open a file with a specific program. For instance, --!/bin/py at the top of a Python script, or --!paint to load a paint file directly into the paint program when launched. :)

commented

Related? #547

commented

One'd probably would be able to get away with standard hashbangs - the Lua parser is smart enough to skip them.

This should be pretty easy to implement - one'd just need to read the first line in the file before the shell actually executes the program, and check if it starts with "#!".

https://github.com/SquidDev-CC/CC-Tweaked/blob/mc-1.15.x/src/main/resources/data/computercraft/lua/rom/programs/shell.lua#L70

If it matches, just tokenize the string and pass that + file name + args to execute again. We probably want to limit the recursion depth (say to 10 or something sane) to avoid crashing with a file foo.lua starting with #! foo.lua.