1
1
mirror of https://git.shadowkat.net/izaya/OC-PsychOS2.git synced 2024-11-22 20:10:34 -05:00
OC-PsychOS2/exec/shell.lua

55 lines
1.3 KiB
Lua
Raw Normal View History

local serial = require "serialization"
local event = require "event"
2019-07-14 06:52:56 -04:00
print(pcall(function()
2018-11-02 12:05:41 -04:00
local shenv = {}
function shenv.quit()
os.setenv("run",nil)
end
shenv.cd = os.chdir
shenv.mkdir = fs.makeDirectory
local function findPath(name)
path = os.getenv("PATH") or "/boot/exec"
for l in path:gmatch("[^\n]+") do
if fs.exists(l.."/"..name) then
return l.."/"..name
elseif fs.exists(l.."/"..name..".lua") then
return l.."/"..name..".lua"
end
end
end
setmetatable(shenv,{__index=function(_,k)
local fp = findPath(k)
if _G[k] then
return _G[k]
elseif fp then
return function(...)
local tA = {...}
local pid = os.spawnfile(fp,fp,table.unpack(tA))
2019-12-16 00:43:32 -05:00
local tE = {event.pull("process_finished",pid)}
if tE[1] == true then
table.remove(tE,1)
end
return table.unpack(tE)
end
end
end})
print(_VERSION)
os.setenv("run",true)
while os.getenv("run") do
io.write(string.format("%s:%s> ",os.getenv("HOSTNAME") or "localhost",(os.getenv("PWD") or _VERSION)))
local input=io.read()
if input:sub(1,1) == "=" then
input = "return "..input:sub(2)
end
tResult = {pcall(load(input,"shell","t",shenv))}
if tResult[1] == true then table.remove(tResult,1) end
2018-11-02 12:05:41 -04:00
for k,v in pairs(tResult) do
if type(v) == "table" then
print(serial.serialize(v,true))
else
print(v)
end
2018-11-02 12:05:41 -04:00
end
end
2019-07-14 06:52:56 -04:00
end))