mirror of
https://github.com/folke/snacks.nvim
synced 2025-12-23 08:47:57 +00:00
feat(picker): add author field to git log (#2295)
## 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)
<!--
If this PR fixes any issues, please link to the issue here.
- Fixes #<issue_number>
-->
## Screenshots
<img width="760" height="842" alt="Screenshot 2025-10-13 at 11 03 28 PM"
src="https://github.com/user-attachments/assets/e57278aa-0fcd-4513-981d-fe8cfe078c64"
/>
<!-- Add screenshots of the changes if applicable. -->
---------
Co-authored-by: Folke Lemaitre <folke.lemaitre@gmail.com>
This commit is contained in:
parent
a5d45d543e
commit
2cf864aaa1
4 changed files with 10 additions and 4 deletions
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue