diff --git a/sys/apps/edit.lua b/sys/apps/edit.lua index bc3e389..2ba8ef1 100644 --- a/sys/apps/edit.lua +++ b/sys/apps/edit.lua @@ -1,13 +1,18 @@ --- Get file to edit +shell.setCompletionFunction(shell.getRunningProgram(), function(shell, index, text) + if index == 1 then + return fs.complete(text, shell.dir(), true, false) + end +end) + local tArgs = { ... } if #tArgs == 0 then error( "Usage: edit " ) end -- Error checking -local sPath = shell.resolve( tArgs[1] ) -local bReadOnly = fs.isReadOnly( sPath ) -if fs.exists( sPath ) and fs.isDir( sPath ) then +local sPath = shell.resolve(tArgs[1]) +local bReadOnly = fs.isReadOnly(sPath) +if fs.exists(sPath) and fs.isDir(sPath) then error( "Cannot edit a directory." ) end diff --git a/sys/apps/webapp.lua b/sys/apps/webapp.lua new file mode 100644 index 0000000..0cd7173 --- /dev/null +++ b/sys/apps/webapp.lua @@ -0,0 +1,53 @@ +local args = { ... } +local GIT_USER = 'kepler155c' +local GIT_REPO = 'opus' +local GIT_BRANCH = 'develop' +local BASE = 'https://raw.githubusercontent.com/kepler155c/opus/develop/' + +local function dourl(env, url) + local h = http.get(url) + if h then + local fn, m = load(h.readAll(), url, nil, env) + h.close() + if fn then + return fn() + end + end + error('Failed to download ' .. url) +end + +local s, m = pcall(function() + + _G.requireInjector = dourl(getfenv(1), BASE .. 'sys/apis/injector.lua') + + local function mkenv() + local env = { } + for k,v in pairs(getfenv(1)) do + env[k] = v + end + setmetatable(env, { __index = _G }) + return env + end + + -- install vfs + dourl(mkenv(), BASE .. 'sys/extensions/vfs.lua') + + -- install filesystem + fs.mount('', 'gitfs', GIT_USER, GIT_REPO, GIT_BRANCH) + + -- start program + local file = table.remove(args, 1) + + local s, m = os.run(mkenv(), file or 'startup', unpack(args)) + if not s and m then + error(m) + end +end) + +if not s and m then + printError(m) +end + +if fs.restore then + fs.restore() +end