diff --git a/modules/lib/fs.lua b/modules/lib/fs.lua index 0e6f100..9da5ca9 100644 --- a/modules/lib/fs.lua +++ b/modules/lib/fs.lua @@ -77,6 +77,7 @@ do return false end function fs.list(s) + s=s or "" local _,d,p = fs.resolve(s) if not d then local kt = {} @@ -104,3 +105,14 @@ do return fT[d].isDirectory(p) end end +function fs.cd(p) + if p:sub(1,1) ~= "/" then + p=(os.getenv("PWD") or "").."/"..p + end + p=fs.simplify(p) + if fs.exists(p) and fs.isdir(p) then + os.setenv("PWD",p) + else + error("non-existent/not a dir") + end +end diff --git a/modules/lib/shutil.lua b/modules/lib/shutil.lua index a960940..38e5207 100644 --- a/modules/lib/shutil.lua +++ b/modules/lib/shutil.lua @@ -1,12 +1,6 @@ -function cd(p) - os.setenv("PWD",fs.simplify((os.getenv("PWD") or "").."/"..p)) -end +cd=fs.cd +rm=fs.rm +mkdir=fs.mkdir function ls(p) for k,v in ipairs(fs.list(p)) do print(v) end end -function rm(p) - fs.rm(p) -end -function mkdir(p) - fs.mkdir(p) -end