2021-03-21 16:41:23 +00:00
|
|
|
-- The preload file initializes everything else for our shell
|
|
|
|
-- Currently it just adds our builtins
|
|
|
|
|
|
|
|
local fs = require 'fs'
|
|
|
|
local commander = require 'commander'
|
2021-03-31 03:58:12 +00:00
|
|
|
local bait = require 'bait'
|
2021-03-21 16:41:23 +00:00
|
|
|
|
2021-03-31 17:46:22 +00:00
|
|
|
commander.register('cd', function (args)
|
|
|
|
bait.throw('cd', args)
|
|
|
|
if #args > 0 then
|
|
|
|
local path = ''
|
|
|
|
for i = 1, #args do
|
|
|
|
path = path .. tostring(args[i]) .. ' '
|
|
|
|
end
|
|
|
|
|
|
|
|
local ok, err = pcall(function() fs.cd(path) end)
|
2021-03-31 03:58:12 +00:00
|
|
|
if not ok then
|
|
|
|
if err == 1 then
|
2021-03-31 03:59:59 +00:00
|
|
|
print('directory does not exist')
|
2021-03-31 03:58:12 +00:00
|
|
|
end
|
2021-03-31 17:46:22 +00:00
|
|
|
bait.throw('command.fail', nil)
|
|
|
|
else bait.throw('command.success', nil) end
|
2021-03-31 03:59:59 +00:00
|
|
|
return
|
2021-03-21 16:41:23 +00:00
|
|
|
end
|
2021-03-31 03:59:59 +00:00
|
|
|
fs.cd(os.getenv 'HOME')
|
2021-03-31 17:46:22 +00:00
|
|
|
bait.throw('command.success', nil)
|
2021-03-21 16:41:23 +00:00
|
|
|
end)
|