From 204d50d73c69640cc2075bda09f9538fd0c60876 Mon Sep 17 00:00:00 2001 From: TorchedSammy <38820196+TorchedSammy@users.noreply.github.com> Date: Wed, 31 Mar 2021 13:46:22 -0400 Subject: [PATCH] feat(preload/cd): throw command hooks in cd command and add support for folders with spaces --- preload.lua | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/preload.lua b/preload.lua index 254a142..9032f2d 100644 --- a/preload.lua +++ b/preload.lua @@ -5,17 +5,23 @@ local fs = require 'fs' local commander = require 'commander' local bait = require 'bait' -commander.register('cd', function (path) - if #path == 1 then - local ok, err = pcall(function() fs.cd(path[1]) end) +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) if not ok then if err == 1 then print('directory does not exist') end - end - bait.throw('cd', path) + bait.throw('command.fail', nil) + else bait.throw('command.success', nil) end return end fs.cd(os.getenv 'HOME') - bait.throw('cd', path) + bait.throw('command.success', nil) end)