From 61bd1b68630859c28e9d6361e7a9427f173fed46 Mon Sep 17 00:00:00 2001 From: rootiest Date: Sat, 3 Aug 2024 22:42:50 -0400 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat(git-blame):=20refactor=20git-b?= =?UTF-8?q?lame=20lualine=20component?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Implement git-blame lualine component via the git-blame plugin initialization --- lua/plugins/util.lua | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/lua/plugins/util.lua b/lua/plugins/util.lua index 5527fa9..78257e0 100644 --- a/lua/plugins/util.lua +++ b/lua/plugins/util.lua @@ -2,6 +2,24 @@ -- -------------------------------- UTILITIES ---------------------------------- -- ----------------------------------------------------------------------------- +-- Function to convert RGB to hexadecimal +local function rgb_to_hex(rgb) + return string.format("#%02x%02x%02x", rgb[1], rgb[2], rgb[3]) +end + +local function get_fg_color(hlgroup) + local hl = vim.api.nvim_get_hl(0, { name = hlgroup, link = false }) + local fg = hl.fg + if fg then + return rgb_to_hex({ + bit.rshift(bit.band(fg, 0xFF0000), 16), + bit.rshift(bit.band(fg, 0x00FF00), 8), + bit.band(fg, 0x0000FF), + }) + end + return nil +end + return { { -- Project management import = "lazyvim.plugins.extras.util.project", @@ -156,5 +174,19 @@ return { { -- Git Blame "f-person/git-blame.nvim", event = "VeryLazy", + opts = function() + -- Get the current lualine configuration + local config = require("lualine").get_config() + local git_blame = require("gitblame") + -- Add Git-blame to lualine_c section + table.insert(config.sections.lualine_c, { + git_blame.get_current_blame_text, + cond = git_blame.is_blame_text_available, + color = { fg = get_fg_color("GitSignsCurrentLineBlame") }, + }) + + -- Apply the new configuration + require("lualine").setup(config) + end, }, }