forked from izaya/OC-PsychOS2
added a cd() builtin to the shell, for changing working directory
This commit is contained in:
parent
ead102f131
commit
12df3de7df
@ -3,6 +3,25 @@ local shenv = {}
|
||||
function shenv.quit()
|
||||
os.setenv("run",nil)
|
||||
end
|
||||
function shenv.cd(p)
|
||||
if p:sub(1,1) == "/" then
|
||||
if fs.list(p) then
|
||||
os.setenv("PWD",p)
|
||||
else
|
||||
print("no such directory: "..p)
|
||||
end
|
||||
else
|
||||
local np = {}
|
||||
for k,v in pairs(fs.segments(os.getenv("PWD").."/"..p)) do
|
||||
if v == ".." then
|
||||
np[#np] = nil
|
||||
else
|
||||
np[#np+1] = v
|
||||
end
|
||||
end
|
||||
os.setenv("PWD","/"..table.concat(np,"/"))
|
||||
end
|
||||
end
|
||||
setmetatable(shenv,{__index=function(_,k)
|
||||
if _G[k] then
|
||||
return _G[k]
|
||||
|
Loading…
Reference in New Issue
Block a user