feat(lualine): new root dir component that only shows when cwd != root_dir
This commit is contained in:
@ -98,4 +98,46 @@ function M.pretty_path(opts)
|
||||
end
|
||||
end
|
||||
|
||||
---@param opts? {cwd:false, subdirectory: true, parent: true, other: true, icon?:string}
|
||||
function M.root_dir(opts)
|
||||
opts = vim.tbl_extend("force", {
|
||||
cwd = false,
|
||||
subdirectory = true,
|
||||
parent = true,
|
||||
other = true,
|
||||
icon = " ",
|
||||
color = Util.ui.fg("Special"),
|
||||
}, opts or {})
|
||||
|
||||
local function get()
|
||||
local cwd = Util.root.cwd()
|
||||
local root = Util.root.get()
|
||||
local name = vim.fs.basename(root)
|
||||
|
||||
if root == cwd then
|
||||
-- root is cwd
|
||||
return opts.cwd and name
|
||||
elseif root:find(cwd, 1, true) == 1 then
|
||||
-- root is subdirectory of cwd
|
||||
return opts.subdirectory and name
|
||||
elseif cwd:find(root, 1, true) == 1 then
|
||||
-- root is parent directory of cwd
|
||||
return opts.parent and name
|
||||
else
|
||||
-- root and cwd are not related
|
||||
return opts.other and name
|
||||
end
|
||||
end
|
||||
|
||||
return {
|
||||
function()
|
||||
return (opts.icon and opts.icon .. " ") .. get()
|
||||
end,
|
||||
cond = function()
|
||||
return type(get()) == "string"
|
||||
end,
|
||||
color = opts.color,
|
||||
}
|
||||
end
|
||||
|
||||
return M
|
||||
|
Reference in New Issue
Block a user