significantly improved the shell; actually forks for processes now, shows the hostname, replaces an = at the start with return ...
This commit is contained in:
parent
b3aa15b580
commit
0dbd1d5f8c
@ -5,15 +5,25 @@ function shenv.quit()
|
|||||||
end
|
end
|
||||||
shenv.cd = os.chdir
|
shenv.cd = os.chdir
|
||||||
shenv.mkdir = fs.makeDirectory
|
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)
|
setmetatable(shenv,{__index=function(_,k)
|
||||||
|
local fp = findPath(k)
|
||||||
if _G[k] then
|
if _G[k] then
|
||||||
return _G[k]
|
return _G[k]
|
||||||
elseif fs.exists("/boot/exec/"..k..".lua") then
|
elseif fp then
|
||||||
--[[
|
|
||||||
local rqid = string.format("shell-%d",math.random(1,99999))
|
local rqid = string.format("shell-%d",math.random(1,99999))
|
||||||
return function(...)
|
return function(...)
|
||||||
local tA = {...}
|
local tA = {...}
|
||||||
local pid = os.spawn(function() computer.pushSignal(rqid,pcall(loadfile("/boot/exec/"..k..".lua"),table.unpack(tA))) end,"/boot/exec/"..k..".lua")
|
local pid = os.spawn(function() computer.pushSignal(rqid,pcall(loadfile(fp),table.unpack(tA))) end,fp)
|
||||||
local tE = {}
|
local tE = {}
|
||||||
repeat
|
repeat
|
||||||
tE = {coroutine.yield()}
|
tE = {coroutine.yield()}
|
||||||
@ -24,17 +34,19 @@ setmetatable(shenv,{__index=function(_,k)
|
|||||||
end
|
end
|
||||||
return table.unpack(tE)
|
return table.unpack(tE)
|
||||||
end
|
end
|
||||||
until tTasks[pid] == nil
|
until not os.taskInfo(pid)
|
||||||
end
|
end
|
||||||
]]--
|
|
||||||
return loadfile("/boot/exec/"..k..".lua")
|
|
||||||
end
|
end
|
||||||
end})
|
end})
|
||||||
print(_VERSION)
|
print(_VERSION)
|
||||||
os.setenv("run",true)
|
os.setenv("run",true)
|
||||||
while os.getenv("run") do
|
while os.getenv("run") do
|
||||||
io.write((os.getenv("PWD") or _VERSION).."> ")
|
io.write(string.format("%s:%s> ",os.getenv("HOSTNAME") or "localhost",(os.getenv("PWD") or _VERSION)))
|
||||||
tResult = {pcall(load(io.read(),"shell","t",shenv))}
|
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
|
if tResult[1] == true then table.remove(tResult,1) end
|
||||||
for k,v in pairs(tResult) do
|
for k,v in pairs(tResult) do
|
||||||
print(v)
|
print(v)
|
||||||
|
Loading…
Reference in New Issue
Block a user