From 44f977d2daedec598b4215ed751c8d72279b1187 Mon Sep 17 00:00:00 2001 From: Fernando Schauenburg Date: Thu, 25 Jul 2024 01:36:14 +0200 Subject: [PATCH] nvim: add plugin 'FabijanZulj/blame.nvim' --- config/nvim/lazy-lock.json | 1 + config/nvim/lua/fschauen/plugins/blame.lua | 58 +++++++++++++++++++ config/nvim/lua/fschauen/plugins/fugitive.lua | 4 +- config/nvim/lua/fschauen/plugins/neogit.lua | 2 +- 4 files changed, 62 insertions(+), 3 deletions(-) create mode 100644 config/nvim/lua/fschauen/plugins/blame.lua diff --git a/config/nvim/lazy-lock.json b/config/nvim/lazy-lock.json index 7b73891..4a769ae 100644 --- a/config/nvim/lazy-lock.json +++ b/config/nvim/lazy-lock.json @@ -1,5 +1,6 @@ { "LuaSnip": { "branch": "master", "commit": "2dbef19461198630b3d7c39f414d09fb07d1fdd2" }, + "blame.nvim": { "branch": "main", "commit": "dedbcdce857f708c63f261287ac7491a893912d0" }, "catppuccin": { "branch": "main", "commit": "9703f227bfab20d04bcee62d2f08f1795723b4ae" }, "cmp-buffer": { "branch": "main", "commit": "3022dbc9166796b644a841a02de8dd1cc1d311fa" }, "cmp-cmdline": { "branch": "main", "commit": "8ee981b4a91f536f52add291594e89fb6645e451" }, diff --git a/config/nvim/lua/fschauen/plugins/blame.lua b/config/nvim/lua/fschauen/plugins/blame.lua new file mode 100644 index 0000000..c5b29f4 --- /dev/null +++ b/config/nvim/lua/fschauen/plugins/blame.lua @@ -0,0 +1,58 @@ +return { + "FabijanZulj/blame.nvim", + + cmd = "BlameToggle", + + keys = { + { + "gb", + "BlameToggle", + desc = require("fschauen.util.icons").ui.Git .. " [g]it [b]lame (blame.nvim)", + }, + }, + + opts = { + -- Using  (0xEACC) instead of - (0x2D) in `date_format` because `blame.nvim` + -- constructs each line and then uses `string.find({s}, {pattern})` to find + -- the position of the date in order to set the highlight. The normal dash + -- (0x2D) is a magic character in {pattern} and prevents the date from being + -- found and thus the highlight fails. Escaping the dash doesn't work because + -- the escape sequence would be visible in the final output, so my + -- workaround is to use a symbol that _looks like_ a dash, but isn't one. + date_format = "%Y%m%d", + + commit_detail_view = "tab", -- Open commits in a new tab. + + mappings = { + commit_info = { "i", "K" }, + }, + + -- The default format uses _committer_ time, but I want _author_ time + -- (when I do rebases, I am interested in the original commit). A custom + -- formatting function also allows me to slightly tweak the final output. + format_fn = function(commit, config, idx) + local hash = string.sub(commit.hash, 1, 7) + + if hash == "0000000" then + return { + idx = idx, + values = { + { textValue = "·······", hl = "Comment" }, + { textValue = "Not commited", hl = "Comment" }, + }, + format = "%s %s", + } + end + + return { + idx = idx, + values = { + { textValue = hash, hl = hash }, + { textValue = os.date(config.date_format, commit.author_time), hl = hash }, + { textValue = commit.author, hl = hash }, + }, + format = "%s %s %s", + } + end, + }, +} diff --git a/config/nvim/lua/fschauen/plugins/fugitive.lua b/config/nvim/lua/fschauen/plugins/fugitive.lua index aa5f69e..ed3e6fb 100644 --- a/config/nvim/lua/fschauen/plugins/fugitive.lua +++ b/config/nvim/lua/fschauen/plugins/fugitive.lua @@ -7,8 +7,8 @@ return { local icon = require("fschauen.util.icons").ui.Git return { -- stylua: ignore start - { "gS", "tab Git", desc = icon.." [S]status (fugitive)" }, - { "gb", "Git blame", desc = icon.." [b]lame (fugitive)" }, + { "gS", "tab Git", desc = icon.." [g]it [S]status (fugitive)" }, + { "gB", "Git blame", desc = icon.." [g]it [B]lame (fugitive)" }, -- stylua: ignore end } end, diff --git a/config/nvim/lua/fschauen/plugins/neogit.lua b/config/nvim/lua/fschauen/plugins/neogit.lua index b4db747..aee076f 100644 --- a/config/nvim/lua/fschauen/plugins/neogit.lua +++ b/config/nvim/lua/fschauen/plugins/neogit.lua @@ -8,7 +8,7 @@ return { dependencies = "nvim-lua/plenary.nvim", keys = { - { "gs", "Neogit", desc = ui.Git .. " [s]tatus (Neogit)" }, + { "gs", "Neogit", desc = ui.Git .. " [g]it [s]tatus (Neogit)" }, }, opts = {