mirror of
https://github.com/LazyVim/LazyVim.git
synced 2025-06-24 17:58:51 +02:00
feat(lualine): new root dir component that only shows when cwd != root_dir
This commit is contained in:
parent
6f88b8b36f
commit
dfdfcad1aa
1 changed files with 42 additions and 0 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue