diff --git a/Taskfile.yaml b/Taskfile.yaml index 264e7d5..311d7d7 100644 --- a/Taskfile.yaml +++ b/Taskfile.yaml @@ -6,7 +6,7 @@ vars: PREFIX: '{{default "/usr/local" .PREFIX}}' bindir__: '{{.PREFIX}}/bin' BINDIR: '{{default .bindir__ .BINDIR}}' - libdir__: '{{.PREFIX}}/share/hilbish' + libdir__: '' LIBDIR: '{{default .libdir__ .LIBDIR}}' goflags__: '-ldflags "-s -w -X main.dataDir={{.LIBDIR}}"' GOFLAGS: '{{default .goflags__ .GOFLAGS}}' diff --git a/nature/init.lua b/nature/init.lua index cd4fd7a..9b75a27 100644 --- a/nature/init.lua +++ b/nature/init.lua @@ -19,6 +19,7 @@ table.insert(package.searchers, function(module) end) require 'nature.hilbish' +require 'nature.processors' require 'nature.commands' require 'nature.completions' diff --git a/nature/opts/autocd.lua b/nature/opts/autocd.lua index ce68230..32a0a84 100644 --- a/nature/opts/autocd.lua +++ b/nature/opts/autocd.lua @@ -1,18 +1,26 @@ local fs = require 'fs' -local oldShRunner = hilbish.runner.sh -function hilbish.runner.sh(input) - local res = oldShRunner(input) +hilbish.processors.add { + func = function(path) + if hilbish.opts.autocd then + local ok, stat = pcall(fs.stat, path) + if ok and stat.isDir then + local oldPath = hilbish.cwd() - if res.exit ~= 0 and hilbish.opts.autocd then - local ok, stat = pcall(fs.stat, res.input) - if ok and stat.isDir then - -- discard here to not append the cd, which will be in history - local _, exitCode, err = hilbish.runner.sh('cd ' .. res.input) - res.exitCode = exitCode - res.err = err + local absPath = fs.abs(path) + fs.cd(path) + + bait.throw('cd', path, oldPath) + bait.throw('hilbish.cd', absPath, oldPath) + + end + return { + continue = not ok + } + else + return { + continue = true + } end end - - return res -end +} diff --git a/nature/opts/init.lua b/nature/opts/init.lua index d55864f..c1347a4 100644 --- a/nature/opts/init.lua +++ b/nature/opts/init.lua @@ -2,7 +2,7 @@ hilbish.opts = {} local function setupOpt(name, default) hilbish.opts[name] = default - pcall(require, 'nature.opts.' .. name) + local ok, err = pcall(require, 'nature.opts.' .. name) end local defaultOpts = { diff --git a/nature/processors.lua b/nature/processors.lua index 7ad0da0..dc89282 100644 --- a/nature/processors.lua +++ b/nature/processors.lua @@ -1,7 +1,7 @@ -- @module hilbish.processors hilbish.processors = { - list = {} + list = {}, sorted = {} } @@ -20,7 +20,7 @@ end function hilbish.processors.execute(command) local continue = true for _, processor in ipairs(hilbish.processors.list) do - local processed = hilbish.processors.func(command) + local processed = processor.func(command) if processed.command then command = processed.command end if not processed.continue then continue = false diff --git a/nature/runner.lua b/nature/runner.lua index 427fb7e..19b4e06 100644 --- a/nature/runner.lua +++ b/nature/runner.lua @@ -122,6 +122,13 @@ end -- @param input string -- @param priv bool function hilbish.runner.run(input, priv) + bait.throw('command.preprocess', input) + local input, continue = hilbish.processors.execute(input) + if not continue then + finishExec(0, '', true) + return + end + local command = hilbish.aliases.resolve(input) bait.throw('command.preexec', input, command)