2022-05-01 01:22:37 +00:00
|
|
|
local fs = require 'fs'
|
|
|
|
|
|
|
|
function cdHandle(inp)
|
2022-05-30 01:33:52 +00:00
|
|
|
local res = hilbish.runner.lua(inp)
|
2022-05-01 01:22:37 +00:00
|
|
|
|
2022-05-30 01:33:52 +00:00
|
|
|
if not res.err then
|
|
|
|
return res
|
2022-05-01 01:22:37 +00:00
|
|
|
end
|
|
|
|
|
2022-05-30 01:33:52 +00:00
|
|
|
res = hilbish.runner.sh(inp)
|
2022-05-01 01:22:37 +00:00
|
|
|
|
2022-05-30 01:33:52 +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-05-30 01:33:52 +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-05-30 01:33:52 +00:00
|
|
|
return res
|
2022-05-01 01:22:37 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
hilbish.runner.setMode(cdHandle)
|