refactor: setup autocd opt in a better way

with the previous commit allowing users to override
hilbish.runner.sh and it being ran by hilbish, the
code for the autocd opt can just override that
function and do the autocd functionality instead
of reimplementing a hybrid runner.

this means that if any other custom runner wants
autocd functionality they can have it with the sh runner
pull/207/head
TorchedSammy 2022-08-30 23:08:22 -04:00
parent c96605e79c
commit 2e192be2e1
Signed by: sammyette
GPG Key ID: 904FC49417B44DCD
1 changed files with 3 additions and 10 deletions

View File

@ -1,13 +1,8 @@
local fs = require 'fs'
function cdHandle(inp)
local res = hilbish.runner.lua(inp)
if not res.err then
return res
end
res = hilbish.runner.sh(inp)
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)
@ -21,5 +16,3 @@ function cdHandle(inp)
return res
end
hilbish.runner.setMode(cdHandle)