From 2cf864aaa1bc31a4d030a52fe03ebac3e65be65d Mon Sep 17 00:00:00 2001 From: Anthony Qiu Date: Tue, 21 Oct 2025 10:38:24 -0400 Subject: [PATCH] feat(picker): add author field to git log (#2295) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Description Currently in the picker you cant filter git log pickers by author, the only option to do that right now is to pass it into the opts when you call it like lua Snacks.picker.git_log({ author="test" }) but most of the time I would like to filter interactively and also use the field filtering offered by snacks like file:lua$ and with this new change, author:test. ## Related Issue(s) ## Screenshots Screenshot 2025-10-13 at 11 03 28 PM --------- Co-authored-by: Folke Lemaitre --- lua/snacks/picker/config/highlights.lua | 1 + lua/snacks/picker/format.lua | 3 +++ lua/snacks/picker/preview.lua | 5 +++-- lua/snacks/picker/source/git.lua | 5 +++-- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/lua/snacks/picker/config/highlights.lua b/lua/snacks/picker/config/highlights.lua index d26a4942..9a40c64c 100644 --- a/lua/snacks/picker/config/highlights.lua +++ b/lua/snacks/picker/config/highlights.lua @@ -57,6 +57,7 @@ Snacks.util.set_hl({ GitBranchCurrent = "Number", GitDate = "Special", GitIssue = "Number", + GitAuthor = "Constant", GitType = "Title", -- conventional commit type GitScope = "Italic", -- conventional commit scope GitStatus = "Special", diff --git a/lua/snacks/picker/format.lua b/lua/snacks/picker/format.lua index fe3569d1..c51cd60d 100644 --- a/lua/snacks/picker/format.lua +++ b/lua/snacks/picker/format.lua @@ -212,6 +212,9 @@ function M.git_log(item, picker) msg = body end ret[#ret + 1] = { msg, msg_hl } + if item.author then + ret[#ret + 1] = { " <" .. item.author .. ">", "SnacksPickerGitAuthor" } + end Snacks.picker.highlight.markdown(ret) Snacks.picker.highlight.highlight(ret, { ["#%d+"] = "SnacksPickerGitIssue", diff --git a/lua/snacks/picker/preview.lua b/lua/snacks/picker/preview.lua index 2dea1df4..56cd1616 100644 --- a/lua/snacks/picker/preview.lua +++ b/lua/snacks/picker/preview.lua @@ -321,7 +321,7 @@ function M.git_log(ctx) ctx, "--no-pager", "log", - "--pretty=format:%h %s (%ch)", + "--pretty=format:%h %s (%ch) <%an>", "--abbrev-commit", "--decorate", "--date=short", @@ -335,7 +335,7 @@ function M.git_log(ctx) ft = "git", ---@param text string add = function(text) - local commit, msg, date = text:match("^(%S+) (.*) %((.*)%)$") + local commit, msg, date, author = text:match("^(%S+) (.*) %((.*)%) <(.*)>$") if commit then row = row + 1 local hl = Snacks.picker.format.git_log({ @@ -345,6 +345,7 @@ function M.git_log(ctx) commit = commit, msg = msg, date = date, + author = author, }, ctx.picker) Snacks.picker.highlight.set(ctx.buf, ns, row, hl) end diff --git a/lua/snacks/picker/source/git.lua b/lua/snacks/picker/source/git.lua index 8de2b849..bdc062a9 100644 --- a/lua/snacks/picker/source/git.lua +++ b/lua/snacks/picker/source/git.lua @@ -94,7 +94,7 @@ function M.log(opts, ctx) local args = git_args( opts.args, "log", - "--pretty=format:%h %s (%ch)", + "--pretty=format:%h %s (%ch) <%an>", "--abbrev-commit", "--decorate", "--date=short", @@ -168,7 +168,7 @@ function M.log(opts, ctx) args = args, ---@param item snacks.picker.finder.Item transform = function(item) - local commit, msg, date = item.text:match("^(%S+) (.*) %((.*)%)$") + local commit, msg, date, author = item.text:match("^(%S+) (.*) %((.*)%) <(.*)>$") if not commit then Snacks.notify.error(("failed to parse log item:\n%q"):format(item.text)) return false @@ -177,6 +177,7 @@ function M.log(opts, ctx) item.commit = commit item.msg = msg item.date = date + item.author = author item.file = file item.files = renames end,