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}}'
|
PREFIX: '{{default "/usr/local" .PREFIX}}'
|
||||||
bindir__: '{{.PREFIX}}/bin'
|
bindir__: '{{.PREFIX}}/bin'
|
||||||
BINDIR: '{{default .bindir__ .BINDIR}}'
|
BINDIR: '{{default .bindir__ .BINDIR}}'
|
||||||
libdir__: '{{.PREFIX}}/share/hilbish'
|
libdir__: ''
|
||||||
LIBDIR: '{{default .libdir__ .LIBDIR}}'
|
LIBDIR: '{{default .libdir__ .LIBDIR}}'
|
||||||
goflags__: '-ldflags "-s -w -X main.dataDir={{.LIBDIR}}"'
|
goflags__: '-ldflags "-s -w -X main.dataDir={{.LIBDIR}}"'
|
||||||
GOFLAGS: '{{default .goflags__ .GOFLAGS}}'
|
GOFLAGS: '{{default .goflags__ .GOFLAGS}}'
|
||||||
|
@ -19,6 +19,7 @@ table.insert(package.searchers, function(module)
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
require 'nature.hilbish'
|
require 'nature.hilbish'
|
||||||
|
require 'nature.processors'
|
||||||
|
|
||||||
require 'nature.commands'
|
require 'nature.commands'
|
||||||
require 'nature.completions'
|
require 'nature.completions'
|
||||||
|
@ -1,18 +1,26 @@
|
|||||||
local fs = require 'fs'
|
local fs = require 'fs'
|
||||||
|
|
||||||
local oldShRunner = hilbish.runner.sh
|
hilbish.processors.add {
|
||||||
function hilbish.runner.sh(input)
|
func = function(path)
|
||||||
local res = oldShRunner(input)
|
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 absPath = fs.abs(path)
|
||||||
local ok, stat = pcall(fs.stat, res.input)
|
fs.cd(path)
|
||||||
if ok and stat.isDir then
|
|
||||||
-- discard here to not append the cd, which will be in history
|
bait.throw('cd', path, oldPath)
|
||||||
local _, exitCode, err = hilbish.runner.sh('cd ' .. res.input)
|
bait.throw('hilbish.cd', absPath, oldPath)
|
||||||
res.exitCode = exitCode
|
|
||||||
res.err = err
|
end
|
||||||
|
return {
|
||||||
|
continue = not ok
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return {
|
||||||
|
continue = true
|
||||||
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
}
|
||||||
return res
|
|
||||||
end
|
|
||||||
|
@ -2,7 +2,7 @@ hilbish.opts = {}
|
|||||||
|
|
||||||
local function setupOpt(name, default)
|
local function setupOpt(name, default)
|
||||||
hilbish.opts[name] = default
|
hilbish.opts[name] = default
|
||||||
pcall(require, 'nature.opts.' .. name)
|
local ok, err = pcall(require, 'nature.opts.' .. name)
|
||||||
end
|
end
|
||||||
|
|
||||||
local defaultOpts = {
|
local defaultOpts = {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
-- @module hilbish.processors
|
-- @module hilbish.processors
|
||||||
|
|
||||||
hilbish.processors = {
|
hilbish.processors = {
|
||||||
list = {}
|
list = {},
|
||||||
sorted = {}
|
sorted = {}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -20,7 +20,7 @@ end
|
|||||||
function hilbish.processors.execute(command)
|
function hilbish.processors.execute(command)
|
||||||
local continue = true
|
local continue = true
|
||||||
for _, processor in ipairs(hilbish.processors.list) do
|
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 processed.command then command = processed.command end
|
||||||
if not processed.continue then
|
if not processed.continue then
|
||||||
continue = false
|
continue = false
|
||||||
|
@ -122,6 +122,13 @@ end
|
|||||||
-- @param input string
|
-- @param input string
|
||||||
-- @param priv bool
|
-- @param priv bool
|
||||||
function hilbish.runner.run(input, priv)
|
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)
|
local command = hilbish.aliases.resolve(input)
|
||||||
bait.throw('command.preexec', input, command)
|
bait.throw('command.preexec', input, command)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user