--[[
	cLinux : Lore of the Day!
	Made by Piorjade, daelvn

	NAME:        /bin/cd
	CATEGORY:    Binary
	SET:         Core Binary
	VERSION:     01:alpha0
	DESCRIPTION:
		This program lists changes the current directory to
		the specified path.
]]--

local tArgs = {...}

if #tArgs > 1 or tArgs[1] == "." then
	print("Usage:")
	print("		cd <path>")
else
	if tArgs[1] == "-" then
		local oldpwd = _G["OLDPWD"]
		if oldpwd == nil then
			printError("OLDPWD isn't set.")
		else
			tArgs[1] = oldpwd
		end
	elseif tArgs[1] == nil then
		local usr = lib.perm.permission.getCurrentUser()
		tArgs[1] = "/home/"..usr.."/"
	end

	_put("OLDPWD", shell.dir())

	if tArgs[1] ~= ".." then
		local ok = shell.setDir(tArgs[1])
		if ok == false then
			printError("Not a directory.")
		end
	elseif tArgs[1] == ".." then
		local p = fs.getDir(shell.dir())
		--[[if string.find(p, "/") == 1 then
			p = "/"..p
		end]]
		local ok = shell.setDir(p)
		if ok == false then
			printError("Not a directory.")
		end
	end
end