mirror of https://github.com/Hilbis/Hilbish
fix(cd): correctly report error
parent
86013e6576
commit
b97e1efa8d
12
preload.lua
12
preload.lua
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue