mirror of
https://git.shadowkat.net/izaya/OC-PsychOS2.git
synced 2024-11-26 04:57:24 -05:00
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()
|
function shenv.quit()
|
||||||
os.setenv("run",nil)
|
os.setenv("run",nil)
|
||||||
end
|
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)
|
setmetatable(shenv,{__index=function(_,k)
|
||||||
if _G[k] then
|
if _G[k] then
|
||||||
return _G[k]
|
return _G[k]
|
||||||
|
Loading…
Reference in New Issue
Block a user