1
1
mirror of https://git.shadowkat.net/izaya/OC-PsychOS2.git synced 2024-11-22 12:04:20 -05:00

moved cd out of the shell and into the os library as os.chdir

This commit is contained in:
XeonSquared 2019-11-06 14:28:40 +11:00
parent c3347fa188
commit ff321804ee
4 changed files with 22 additions and 21 deletions

View File

@ -1,12 +1,12 @@
xpcall(function() xpcall(function()
os.setenv("PWD","/boot")
os.spawnfile("/boot/service/getty.lua") os.spawnfile("/boot/service/getty.lua")
coroutine.yield() coroutine.yield()
for k,v in pairs(fs.list("/dev/")) do for k,v in pairs(fs.list("/dev/")) do
if v:sub(1,3) == "tty" then if v:sub(1,3) == "tty" then
dprint(tostring(io.input("/dev/"..v))) dprint(tostring(io.input("/dev/"..v)))
dprint(tostring(io.output("/dev/"..v))) dprint(tostring(io.output("/dev/"..v)))
io.write("PsychOS v2.0a1 - ") io.write(_OSVERSION.." - "..tostring(math.floor(computer.totalMemory()/1024)).."K RAM")
print(tostring(math.floor(computer.totalMemory()/1024)).."K RAM")
os.spawnfile("/boot/exec/shell.lua") os.spawnfile("/boot/exec/shell.lua")
end end
end end

View File

@ -3,25 +3,7 @@ local shenv = {}
function shenv.quit() function shenv.quit()
os.setenv("run",nil) os.setenv("run",nil)
end end
function shenv.cd(p) shenv.cd = os.chdir
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]

View File

@ -1,6 +1,7 @@
--#include "module/chatbox-dprint.lua" --#include "module/chatbox-dprint.lua"
--#include "module/syslog.lua" --#include "module/syslog.lua"
--#include "module/sched.lua" --#include "module/sched.lua"
--#include "module/osutil.lua"
--#include "module/fs.lua" --#include "module/fs.lua"
--#include "module/newio.lua" --#include "module/newio.lua"
--#include "module/devfs.lua" --#include "module/devfs.lua"

18
module/osutil.lua Normal file
View File

@ -0,0 +1,18 @@
function os.chdir(p) -- changes the current working directory of the calling process to the directory specified in *p*, returning true or false, error
if not (p:sub(1,1) == "/") then
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
p = "/"..table.concat(np,"/")
end
if fs.exists(p) and fs.list(p) then
os.setenv("PWD",p)
else
return false, "no such directory"
end
end