nvim/lua/plugins/editor_lua_line.lua
RingOfStorms (Joshua Bell) e561408f16 update deps
2025-05-06 16:02:22 -05:00

140 lines
3.4 KiB
Lua

local function lsp_clients()
local clients = {}
for _, client in pairs(vim.lsp.get_clients()) do
clients[#clients + 1] = client.name
end
table.sort(clients)
return table.concat(clients, ""), ""
end
local function langs()
local l = {}
for _, client in pairs(vim.lsp.get_clients()) do
local out = nil
if client.name == "pyright" then
out = vim.fn.system({ "python", "-V" })
elseif client.name == "tsserver" or client.name == "ts_ls" then
out = "node " .. vim.fn.system({ "node", "--version" })
end
if out ~= nil and out ~= "" then
l[#l + 1] = vim.trim(out)
end
end
table.sort(l)
return table.concat(l, ""), ""
end
local last_blame = nil
local last_blame_time = vim.loop.now()
local function gitblame()
local d = vim.b.gitsigns_blame_line_dict
if d then
last_blame = d
last_blame_time = vim.loop.now()
elseif vim.loop.now() - last_blame_time <= 2000 then
d = last_blame
end
if d then
local ok, res = pcall(os.date, "%d %b %y", d.committer_time)
return d.committer:sub(1, 12) .. " - " .. (ok and res or d.committer_time)
end
return ""
end
local function smart_tab_name()
local filepath = vim.fn.expand("%:p")
local parent_dir = vim.fn.fnamemodify(filepath, ":h:t")
local filename = vim.fn.fnamemodify(filepath, ":t")
return parent_dir .. "/" .. filename
end
return {
"nvim-lualine/lualine.nvim",
-- dependencies = { { "folke/noice.nvim", optional = true } },
lazy = false,
opts = function()
return {
options = {
theme = "codedark",
section_separators = { left = "", right = "" },
component_separators = "|",
},
sections = {
lualine_a = { "mode" },
lualine_b = {
"branch",
"filename",
},
lualine_c = {
"diff",
"diagnostics",
{ "reg_recording", icon = { "󰻃" }, color = { fg = "#D37676" } },
{ gitblame, color = { fg = "#696969" } },
},
lualine_x = {
lsp_clients,
langs,
"encoding",
"filetype",
"filesize",
},
lualine_y = { "searchcount", "selectioncount" },
lualine_z = { "location" },
},
winbar = {
lualine_a = {
{
smart_tab_name,
symbols = {
modified = "", -- Text to show when the file is modified.
readonly = "[-]", -- Text to show when the file is non-modifiable or readonly.
unnamed = "[No Name]", -- Text to show for unnamed buffers.
newfile = "[New]", -- Text to show for newly created file before first write
},
},
},
lualine_b = {
"mode",
},
},
inactive_winbar = {
lualine_a = {
{
smart_tab_name,
symbols = {
modified = "", -- Text to show when the file is modified.
readonly = "[-]", -- Text to show when the file is non-modifiable or readonly.
unnamed = "[No Name]", -- Text to show for unnamed buffers.
newfile = "[New]", -- Text to show for newly created file before first write
},
},
},
},
}
end,
config = function(_, opts)
require("lualine").setup(opts)
local ref = function()
require("lualine").refresh({
place = { "statusline" },
})
end
local group = vim.api.nvim_create_augroup("myconfig-lua-line-group", { clear = true })
vim.api.nvim_create_autocmd("RecordingEnter", {
group = group,
callback = ref,
})
vim.api.nvim_create_autocmd("RecordingLeave", {
group = group,
callback = function()
local timer = vim.loop.new_timer()
timer:start(50, 0, vim.schedule_wrap(ref))
end,
})
end,
}