mirror of
https://github.com/Hilbis/Hilbish
synced 2025-03-13 18:00:41 +00:00
this adds `hilbish.opts`, a table to set simple options akin to shopt or setopt on other shells. this commit specifically also includes the autocd opt, which functions the way you expect it to to set opts, simply do `hilbish.opts.name = val`, where `name` is the opt you want to set and `val` being the opt setting. ie: `hilbish.opts.autocd = true` to turn on autocd
24 lines
497 B
Lua
24 lines
497 B
Lua
local fs = require 'fs'
|
|
|
|
function cdHandle(inp)
|
|
local input, exit, err = hilbish.runner.lua(inp)
|
|
|
|
if not err then
|
|
return input, exit, err
|
|
end
|
|
|
|
input, exit, err = hilbish.runner.sh(inp)
|
|
|
|
if exit ~= 0 and hilbish.opts.autocd then
|
|
local ok, stat = pcall(fs.stat, input)
|
|
if ok and stat.isDir then
|
|
-- discard here to not append the cd, which will be in history
|
|
_, exit, err = hilbish.runner.sh('cd ' .. input)
|
|
end
|
|
end
|
|
|
|
return input, exit, err
|
|
end
|
|
|
|
hilbish.runner.setMode(cdHandle)
|