mirror of
https://github.com/Hilbis/Hilbish
synced 2025-04-20 20:43:23 +00:00
fix: make processor work properly, implement in exec code
This commit is contained in:
parent
cd263ec7a0
commit
38b5aec99e
@ -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}}'
|
||||
|
@ -19,6 +19,7 @@ table.insert(package.searchers, function(module)
|
||||
end)
|
||||
|
||||
require 'nature.hilbish'
|
||||
require 'nature.processors'
|
||||
|
||||
require 'nature.commands'
|
||||
require 'nature.completions'
|
||||
|
@ -1,18 +1,26 @@
|
||||
local fs = require 'fs'
|
||||
|
||||
local oldShRunner = hilbish.runner.sh
|
||||
function hilbish.runner.sh(input)
|
||||
local res = oldShRunner(input)
|
||||
|
||||
if res.exit ~= 0 and hilbish.opts.autocd then
|
||||
local ok, stat = pcall(fs.stat, res.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
|
||||
-- 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
|
||||
end
|
||||
end
|
||||
local oldPath = hilbish.cwd()
|
||||
|
||||
local absPath = fs.abs(path)
|
||||
fs.cd(path)
|
||||
|
||||
bait.throw('cd', path, oldPath)
|
||||
bait.throw('hilbish.cd', absPath, oldPath)
|
||||
|
||||
return res
|
||||
end
|
||||
return {
|
||||
continue = not ok
|
||||
}
|
||||
else
|
||||
return {
|
||||
continue = true
|
||||
}
|
||||
end
|
||||
end
|
||||
}
|
||||
|
@ -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 = {
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user