mirror of
https://github.com/folke/snacks.nvim
synced 2025-08-04 18:58:12 +00:00
feat(picker): added git_branches
picker. Closes #614
This commit is contained in:
parent
903431903b
commit
8563dfce68
8 changed files with 196 additions and 7 deletions
|
@ -86,6 +86,7 @@ end
|
|||
---@type snacks.picker.finder
|
||||
function M.status(opts)
|
||||
local args = {
|
||||
"--no-pager",
|
||||
"status",
|
||||
"-uall",
|
||||
"--porcelain=v1",
|
||||
|
@ -154,4 +155,26 @@ function M.diff(opts)
|
|||
end
|
||||
end
|
||||
|
||||
---@param opts snacks.picker.Config
|
||||
---@type snacks.picker.finder
|
||||
function M.branches(opts)
|
||||
local args = { "--no-pager", "branch", "--no-color", "-vvl" }
|
||||
local cwd = vim.fs.normalize(opts and opts.cwd or uv.cwd() or ".") or nil
|
||||
cwd = Snacks.git.get_root(cwd)
|
||||
return require("snacks.picker.source.proc").proc(vim.tbl_deep_extend("force", {
|
||||
cwd = cwd,
|
||||
cmd = "git",
|
||||
args = args,
|
||||
---@param item snacks.picker.finder.Item
|
||||
transform = function(item)
|
||||
local status, branch, commit, msg = item.text:match("^(.)%s(%S+)%s+([a-zA-Z0-9]+)%s*(.*)$")
|
||||
item.cwd = cwd
|
||||
item.current = status == "*"
|
||||
item.branch = branch
|
||||
item.commit = commit
|
||||
item.msg = msg
|
||||
end,
|
||||
}, opts or {}))
|
||||
end
|
||||
|
||||
return M
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue