2
2
mirror of https://github.com/Hilbis/Hilbish synced 2025-04-20 20:43:23 +00:00
Hilbish/nature/opts/autocd.lua

27 lines
445 B
Lua

local fs = require 'fs'
hilbish.processors.add {
func = function(path)
if hilbish.opts.autocd then
local ok, stat = pcall(fs.stat, path)
if ok and stat.isDir then
local oldPath = hilbish.cwd()
local absPath = fs.abs(path)
fs.cd(path)
bait.throw('cd', path, oldPath)
bait.throw('hilbish.cd', absPath, oldPath)
end
return {
continue = not ok
}
else
return {
continue = true
}
end
end
}