Repository navigation
[Mini.pick] git hunks - Mark as git add #1874
Contributing guidelines
Module(s)mini.pick QuestionHi there, I'm a bit new to this, I want to select files from :Pick git_hunks (To view unstaged files) and when I mark one, this file will be added to stage like (git add filename), I used this feature in telescope, but I don't know how I can do it in Mini.pick. So my question is: Is it possible? mark files and add these to the git stage. |
Replies: 4 comments 2 replies
|
Yes, this (marking hunks, not files, to later apply them) is possible with writing custom require('mini.extra').setup()
local stage_hunk_item = function(item)
local patch = vim.deepcopy(item.header)
vim.list_extend(patch, item.hunk)
local cmd = { 'git', 'apply', '--cached', '-' }
vim.system(cmd, { stdin = patch }):wait()
end
local stage_marked = function(items_marked) vim.tbl_map(stage_hunk_item, items_marked) end
-- NOTE: Make sure `require('mini.pick').setup()` is called prior to this
MiniPick.registry.git_hunks = function(local_opts)
MiniExtra.pickers.git_hunks(local_opts, { source = { choose_marked = stage_marked } })
endSo with this in place:
Note, that this relies on some assumption about the internal structure of items in |
|
Thanks a lot, it is amazing! Also I can to change color to the hunk according hl group? |
|
With what you tell me is enough, I thank you very much. That's just what I needed to know |
-- Custom mini.nvim configuration
now(function()
MiniPick.registry.git_hunks = function(local_opts)
MiniExtra.pickers.git_hunks(local_opts, {
source = {
choose_marked = function(items_marked)
vim.tbl_map(function(item)
local patch = vim.deepcopy(item.header)
vim.list_extend(patch, item.hunk)
local cmd
if local_opts.scope == "staged" then
cmd = { "git", "apply", "--cached", "--reverse", "-" }
else
cmd = { "git", "apply", "--cached", "-" }
end
vim.system(cmd, { stdin = patch }):wait()
end, items_marked)
end,
},
})
end
end)I came up with this snippet to stage and unstage stuff using git after taking a look at your snippet. @echasnovski any chance this action can go to mini.extra for the hunks picker? This can be made the official way to stage and unstage multiple hunks. |
Yes, this (marking hunks, not files, to later apply them) is possible with writing custom
choose_marked. Something like this:So with this in…