From f48272bbea447e9328032c70c0e46392afcdd34a Mon Sep 17 00:00:00 2001 From: sammyette Date: Wed, 23 Apr 2025 18:37:03 -0400 Subject: [PATCH] feat: add names to processors, allow skipping based on name --- nature/opts/autocd.lua | 1 + nature/processors.lua | 31 +++++++++++++++++++++++++------ 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/nature/opts/autocd.lua b/nature/opts/autocd.lua index 32a0a84..2c8a2b7 100644 --- a/nature/opts/autocd.lua +++ b/nature/opts/autocd.lua @@ -1,6 +1,7 @@ local fs = require 'fs' hilbish.processors.add { + name = 'hilbish.autocd', func = function(path) if hilbish.opts.autocd then local ok, stat = pcall(fs.stat, path) diff --git a/nature/processors.lua b/nature/processors.lua index dc89282..660e8bf 100644 --- a/nature/processors.lua +++ b/nature/processors.lua @@ -6,6 +6,10 @@ hilbish.processors = { } function hilbish.processors.add(processor) + if not processor.name then + error 'processor is missing name' + end + if not processor.func then error 'processor is missing function' end @@ -14,17 +18,32 @@ function hilbish.processors.add(processor) table.sort(hilbish.processors.list, function(a, b) return a.priority < b.priority end) end +local function contains(search, needle) + for _, p in ipairs(search) do + if p == needle then + return true + end + end + + return false +end + --- Run all command processors, in order by priority. --- It returns the processed command (which may be the same as the passed command) --- and a boolean which states whether to proceed with command execution. -function hilbish.processors.execute(command) +function hilbish.processors.execute(command, opts) + opts = opts or {} + opts.skip = opts.skip or {} + local continue = true for _, processor in ipairs(hilbish.processors.list) do - local processed = processor.func(command) - if processed.command then command = processed.command end - if not processed.continue then - continue = false - break + if not contains(opts.skip, processor.name) then + local processed = processor.func(command) + if processed.command then command = processed.command end + if not processed.continue then + continue = false + break + end end end