2022-04-30 21:22:37 -04:00
|
|
|
local fs = require 'fs'
|
|
|
|
|
2022-08-30 23:08:22 -04:00
|
|
|
local oldShRunner = hilbish.runner.sh
|
|
|
|
function hilbish.runner.sh(input)
|
|
|
|
local res = oldShRunner(input)
|
2022-04-30 21:22:37 -04:00
|
|
|
|
2022-06-02 19:33:30 -07:00
|
|
|
if res.exit ~= 0 and hilbish.opts.autocd then
|
|
|
|
local ok, stat = pcall(fs.stat, res.input)
|
2022-04-30 21:22:37 -04:00
|
|
|
if ok and stat.isDir then
|
|
|
|
-- discard here to not append the cd, which will be in history
|
2022-06-02 19:33:30 -07:00
|
|
|
local _, exitCode, err = hilbish.runner.sh('cd ' .. res.input)
|
|
|
|
res.exitCode = exitCode
|
|
|
|
res.err = err
|
2022-04-30 21:22:37 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-06-02 19:33:30 -07:00
|
|
|
return res
|
2022-04-30 21:22:37 -04:00
|
|
|
end
|