diff --git a/nature/greenhouse/init.lua b/nature/greenhouse/init.lua index 2badfaea..d7bf35de 100644 --- a/nature/greenhouse/init.lua +++ b/nature/greenhouse/init.lua @@ -361,6 +361,8 @@ function Greenhouse:initUi() self = nil bait.release('signal.sigint', sigint) bait.release('signal.resize', resize) + + ansikit.clear() end return Greenhouse diff --git a/nature/init.lua b/nature/init.lua index 9b75a271..ad956a4b 100644 --- a/nature/init.lua +++ b/nature/init.lua @@ -19,7 +19,9 @@ table.insert(package.searchers, function(module) end) require 'nature.hilbish' + require 'nature.processors' +require 'nature.processors.wildcardWarn' require 'nature.commands' require 'nature.completions' diff --git a/nature/processors.lua b/nature/processors/init.lua similarity index 83% rename from nature/processors.lua rename to nature/processors/init.lua index f36d7ace..43ee42d5 100644 --- a/nature/processors.lua +++ b/nature/processors/init.lua @@ -40,11 +40,13 @@ function hilbish.processors.execute(command, opts) for _, processor in ipairs(hilbish.processors.list) do if not contains(opts.skip, processor.name) then local processed = processor.func(command) - if processed.history ~= nil then history = processed.history end - if processed.command then command = processed.command end - if not processed.continue then - continue = false - break + if processed then + if processed.history ~= nil then history = processed.history end + if processed.command then command = processed.command end + if not processed.continue then + continue = false + break + end end end end @@ -54,4 +56,4 @@ function hilbish.processors.execute(command, opts) continue = continue, history = history } -end +end \ No newline at end of file diff --git a/nature/processors/wildcardWarn.lua b/nature/processors/wildcardWarn.lua new file mode 100644 index 00000000..c121ed3d --- /dev/null +++ b/nature/processors/wildcardWarn.lua @@ -0,0 +1,65 @@ +local hilbish = require 'hilbish' +local Greenhouse = require 'nature.greenhouse' +local Page = require 'nature.greenhouse.page' + +print 'wildcard warn loaded' + +local function contains(search, needle) + for _, p in ipairs(search) do + if p:match(needle) then + return p + end + end + + return nil +end + +local stdoutSink = {} +function stdoutSink:write(t) + io.write(t) +end + +function stdoutSink:writeln(t) + print(t) +end + +hilbish.processors.add { + name = 'wildcardWarn', + func = function(commandLine) + local args = string.split(commandLine, ' ') + if args[1] == 'rm' then -- command check + local match1 = contains(args, '%*') + local match2 = contains(args, '/%*') + if match1 or match2 then + local matches = fs.glob(match1 or match2) + if #matches == 0 then + return {continue = true} + end + + ::askWithInfo:: + print 'Detected wildcard with potentially dangerous command.' + print 'Are you sure you want to run this command?' + + ::ask:: + local ans = hilbish.read '(Y/N, L to list files matched with wildcard) ' + ans = ans:lower() + if ans == 'l' then + local gh = Greenhouse(stdoutSink) + local page = Page('Wildcard File List', '') + page.lines = matches + + gh:addPage(page) + gh:initUi() + goto askWithInfo + elseif ans == 'y' then + return {continue = true} + elseif ans == 'n' then + return {continue = false} + else + print 'Invalid answer..' + goto ask + end + end + end + end +} \ No newline at end of file