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