2
2
mirror of https://github.com/Hilbis/Hilbish synced 2025-04-16 02:23:22 +00:00

30 lines
630 B
Lua

local bait = require 'bait'
local commander = require 'commander'
local fs = require 'fs'
local dirs = require 'nature.dirs'
commander.register('cd', function (args, sinks)
local oldPath = hilbish.cwd()
if #args > 1 then
sinks.out:writeln("cd: too many arguments")
return 1
end
local path = args[1] and args[1] or hilbish.home
if path == '-' then
path = dirs.old
sinks.out:writeln(path)
end
local absPath = fs.abs(path)
local ok, err = pcall(function() fs.cd(path) end)
if not ok then
sinks.out:writeln(err)
return 1
end
bait.throw('cd', path, oldPath)
bait.throw('hilbish.cd', absPath, oldPath)
end)