fix(cd): correctly report error

pull/78/head
sammyette 2021-10-17 17:55:41 -04:00
parent 86013e6576
commit b97e1efa8d
No known key found for this signature in database
GPG Key ID: 50EE40A2809851F5
1 changed files with 3 additions and 9 deletions

View File

@ -12,11 +12,7 @@ if shlvl ~= nil then os.setenv('SHLVL', shlvl + 1) else os.setenv('SHLVL', 1) en
-- Builtins -- Builtins
commander.register('cd', function (args) commander.register('cd', function (args)
if #args > 0 then if #args > 0 then
local path = '' local path = table.concat(args, ' '):gsub('$%$','\0'):gsub('${([%w_]+)}', os.getenv)
for i = 1, #args do
path = path .. tostring(args[i]) .. ' '
end
path = path:gsub('$%$','\0'):gsub('${([%w_]+)}', os.getenv)
:gsub('$([%w_]+)', os.getenv):gsub('%z','$'):gsub('^%s*(.-)%s*$', '%1') :gsub('$([%w_]+)', os.getenv):gsub('%z','$'):gsub('^%s*(.-)%s*$', '%1')
if path == '-' then if path == '-' then
@ -27,10 +23,8 @@ commander.register('cd', function (args)
local ok, err = pcall(function() fs.cd(path) end) local ok, err = pcall(function() fs.cd(path) end)
if not ok then if not ok then
if err == 1 then print(err:sub(17))
print('directory does not exist') return 1
end
return err
end end
bait.throw('cd', path) bait.throw('cd', path)
return return