refactor(nvim): use prettypath function from lazyvim utils
This commit is contained in:
1 parent
50a22f5ac0
commit
5193d3bd42
4 files changed
+33
-104
No files matched your search
@@ -2,8 +2,8 @@ return {
|
||||
{
|
||||
"sindrets/diffview.nvim",
|
||||
keys = {
|
||||
{ "<leader>gd", "<cmd>DiffviewFileHistory<CR>", desc = "Diff File History" },
|
||||
{ "<leader>gD", "<cmd>DiffviewOpen<CR>", desc = "Diff View Open" },
|
||||
{ "<leader>gF", "<cmd>DiffviewFileHistory<CR>", desc = "File History (Diff)" },
|
||||
{ "<leader>gd", "<cmd>DiffviewOpen<CR>", desc = "Diff View" },
|
||||
},
|
||||
opts = function(_, opts)
|
||||
local actions = require("diffview.actions")
|
||||
|
||||
@@ -9,6 +9,10 @@ return {
|
||||
{ "<leader>gG", "<cmd>FloatermNew --name=lazygitbuffer --opener=edit --titleposition=center --height=0.85 --width=0.85 --cwd=<buffer> lazygit<CR>", desc = "Lazygit (cwd)" },
|
||||
{ "<leader>cen", "<cmd>FloatermNew --name=node --opener=edit --titleposition=center --wintype=split --height=0.35 node<CR>", desc = "Node" },
|
||||
{ "<leader>cep", "<cmd>FloatermNew --name=python --opener=edit --titleposition=center --wintype=split --height=0.35 python<CR>", desc = "Python" },
|
||||
{ "<leader>gf", function()
|
||||
local git_path = vim.fn.system("git ls-files --full-name " .. vim.api.nvim_buf_get_name(0))
|
||||
vim.api.nvim_command("FloatermNew --name=lazygitroot --opener=edit --titleposition=center --height=0.85 --width=0.85 lazygit -f " .. vim.trim(git_path))
|
||||
end, desc = "File History (LazyGit)" },
|
||||
{ "<S-Right>", "<Esc><Esc><cmd>FloatermNext<CR>", mode = { "t" }, desc = "Next Terminal" },
|
||||
{ "<S-Left>", "<Esc><Esc><cmd>FloatermPrev<CR>", mode = { "t" }, desc = "Prev Terminal" },
|
||||
{ "<A-Right>", "<Esc><Esc><cmd>FloatermLast<CR>", mode = { "t" }, desc = "Last Terminal" },
|
||||
|
||||
@@ -1,84 +1,3 @@
|
||||
local util = require("lazyvim.util")
|
||||
|
||||
-- Format and pretty_path extracted from https://github.com/LazyVim/LazyVim/discussions/2605
|
||||
local function format(component, text, hl_group)
|
||||
if not hl_group then
|
||||
return text
|
||||
end
|
||||
|
||||
---@type table<string, string>
|
||||
component.hl_cache = component.hl_cache or {}
|
||||
local lualine_hl_group = component.hl_cache[hl_group]
|
||||
if not lualine_hl_group then
|
||||
local utils = require("lualine.utils.utils")
|
||||
local mygui = function()
|
||||
local mybold = utils.extract_highlight_colors(hl_group, "bold") and "bold"
|
||||
local myitalic = utils.extract_highlight_colors(hl_group, "italic") and "italic"
|
||||
if mybold and myitalic then
|
||||
return mybold .. "," .. myitalic
|
||||
elseif mybold then
|
||||
return mybold
|
||||
elseif myitalic then
|
||||
return myitalic
|
||||
else
|
||||
return ""
|
||||
end
|
||||
end
|
||||
|
||||
lualine_hl_group = component:create_hl({
|
||||
fg = utils.extract_highlight_colors(hl_group, "fg"),
|
||||
gui = mygui(),
|
||||
}, "LV_" .. hl_group)
|
||||
component.hl_cache[hl_group] = lualine_hl_group
|
||||
end
|
||||
return component:format_hl(lualine_hl_group) .. text .. component:get_default_hl()
|
||||
end
|
||||
|
||||
local function pretty_path(opts)
|
||||
opts = vim.tbl_extend("force", {
|
||||
relative = "cwd",
|
||||
modified_hl = "NeogitGraphBoldYellow",
|
||||
filename_hl = "NeogitGraphBoldWhite",
|
||||
dirpath_hl = "Conceal",
|
||||
}, opts or {})
|
||||
|
||||
return function(self)
|
||||
local path = vim.fn.expand("%:p") --[[@as string]]
|
||||
if path == "" then
|
||||
return ""
|
||||
end
|
||||
|
||||
local root = util.root.get({ normalize = true })
|
||||
local cwd = util.root.cwd()
|
||||
|
||||
if opts.relative == "cwd" and path:find(cwd, 1, true) == 1 then
|
||||
path = path:sub(#cwd + 2)
|
||||
else
|
||||
path = path:sub(#root + 2)
|
||||
end
|
||||
|
||||
local sep = package.config:sub(1, 1)
|
||||
local parts = vim.split(path, "[\\/]")
|
||||
|
||||
if #parts > 3 then
|
||||
parts = { parts[1], "…", parts[#parts - 1], parts[#parts] }
|
||||
end
|
||||
|
||||
if opts.modified_hl and vim.bo.modified then
|
||||
parts[#parts] = format(self, parts[#parts], opts.modified_hl)
|
||||
else
|
||||
parts[#parts] = format(self, parts[#parts], opts.filename_hl)
|
||||
end
|
||||
|
||||
local dirpath = ""
|
||||
if #parts > 1 then
|
||||
dirpath = table.concat({ unpack(parts, 1, #parts - 1) }, sep)
|
||||
dirpath = format(self, dirpath .. sep, opts.dirpath_hl)
|
||||
end
|
||||
return dirpath .. parts[#parts]
|
||||
end
|
||||
end
|
||||
|
||||
local lsp = function()
|
||||
local buf_clients = vim.lsp.get_clients({ bufnr = 0 })
|
||||
if #buf_clients == 0 then
|
||||
@@ -113,7 +32,13 @@ return {
|
||||
opts.options.section_separators = { left = "", right = "" }
|
||||
|
||||
opts.sections.lualine_a = { { "mode", icon = "" } }
|
||||
opts.sections.lualine_c[4] = { pretty_path({ filename_hl = "Bold", modified_hl = "MatchParen" }) }
|
||||
opts.sections.lualine_c[4] = {
|
||||
require("lazyvim.util.lualine").pretty_path({
|
||||
filename_hl = "Bold",
|
||||
modified_hl = "MatchParen",
|
||||
directory_hl = "Conceal",
|
||||
}),
|
||||
}
|
||||
|
||||
table.insert(opts.sections.lualine_x, 2, lsp)
|
||||
table.insert(opts.sections.lualine_x, 2, formatter)
|
||||
|
||||
Reference in new issue
Block a user