57 lines
1.2 KiB
Lua
57 lines
1.2 KiB
Lua
local shutil = {}
|
|
shutil.cd=fs.cd
|
|
shutil.rm=fs.rm
|
|
shutil.mkdir=fs.mkdir
|
|
shutil.cp=fs.cp
|
|
shutil.mv=fs.mv
|
|
function shutil.ls(p)
|
|
for k,v in ipairs(fs.list(p)) do print(v) end
|
|
end
|
|
function shutil.cat(p)
|
|
local f=io.open(p)
|
|
print(f:read("*a"))
|
|
f:close()
|
|
end
|
|
function shutil.ps(f)
|
|
local f=f or ""
|
|
print("PID\tUser\tName")
|
|
for k,v in pairs(os.tasks()) do
|
|
local _,_,uid = os.taskinfo(k)
|
|
if v:find(f) then
|
|
print(tostring(k).."\t"..tostring(uid:sub(1,6)).."\t"..tostring(v))
|
|
end
|
|
end
|
|
end
|
|
function shutil.mem()
|
|
print(" \tTotal\tFree\tUsed")
|
|
io.write("Mem\t")
|
|
io.write(tostring(math.floor(computer.totalMemory()/1024)).."K\t")
|
|
io.write(tostring(math.floor(computer.freeMemory()/1024)).."K\t")
|
|
print(tostring(math.floor((computer.totalMemory()-computer.freeMemory())/1024)).."K\t")
|
|
end
|
|
function shutil.genenv()
|
|
local et = os.genenv()
|
|
for k,v in pairs(shutil) do
|
|
if k ~= "genenv" then
|
|
et[k] = v
|
|
end
|
|
end
|
|
return et
|
|
end
|
|
function loadfile(fn)
|
|
local f=io.open(fn,"rb")
|
|
local S=f:read("*a")
|
|
f:close()
|
|
return load(S,"=("..fn..")","bt",os.genenv())
|
|
end
|
|
function run(fn,...)
|
|
local r = {pcall(loadfile(fn),...)}
|
|
if r[1] == true then
|
|
table.remove(r,1)
|
|
end
|
|
print(table.unpack(r))
|
|
end
|
|
function srun(fn,...)
|
|
spawn(fn,print(pcall(loadfile(fn),...)))
|
|
end
|