feat: cd - changes pwd to previous one

close #53
pull/59/head
Devin Singh 2021-05-27 17:23:15 -05:00
parent 9defa737f4
commit 9573c2732d
1 changed files with 6 additions and 1 deletions

View File

@ -3,6 +3,7 @@
local fs = require 'fs'
local commander = require 'commander'
local bait = require 'bait'
local old_dir = os.getenv "PWD"
-- Builtins
commander.register('cd', function (args)
@ -13,8 +14,12 @@ commander.register('cd', function (args)
path = path .. tostring(args[i]) .. ' '
end
path = path:gsub('$%$','\0'):gsub('${([%w_]+)}', os.getenv)
:gsub('$([%w_]+)', os.getenv):gsub('%z','$')
:gsub('$([%w_]+)', os.getenv):gsub('%z','$'):gsub("%s+", "")
if path == '-' then
path = old_dir
end
old_dir = os.getenv "PWD"
local ok, err = pcall(function() fs.cd(path) end)
if not ok then
if err == 1 then