forked from izaya/OC-PsychOS2
35 lines
857 B
Lua
35 lines
857 B
Lua
|
local shell = {}
|
||
|
shell.include = {"shutil"}
|
||
|
local function shindex(self,k)
|
||
|
if rawget(self,k) then return rawget(self,k) end
|
||
|
for _,v in pairs(os.getenv("INCLUDE") or shell.include) do
|
||
|
if require(v)[k] then return require(v)[k] end
|
||
|
end
|
||
|
if package.loaded[k] then return package.loaded[k] end
|
||
|
return _G[k]
|
||
|
end
|
||
|
|
||
|
function shell.interactive()
|
||
|
local shenv = setmetatable({}, {__index=shindex})
|
||
|
local run = true
|
||
|
while 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
|
||
|
local f, r = load(input, "shell", "t", shenv)
|
||
|
if not f then
|
||
|
print(r)
|
||
|
else
|
||
|
local rt = {pcall(f)}
|
||
|
local rs = table.remove(rt,1)
|
||
|
for k,v in pairs(rt) do
|
||
|
print(tostring(v))
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
|
||
|
return shell
|