From 7cb8ad708fd7f0bf13c0c5c0a66aaca57baf337e Mon Sep 17 00:00:00 2001 From: Ian Liu Date: Wed, 5 Feb 2025 12:39:33 -0800 Subject: [PATCH 1/2] add: confirmation before deleting the branch --- lua/snacks/picker/actions.lua | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lua/snacks/picker/actions.lua b/lua/snacks/picker/actions.lua index bb282f7a2..805ae66df 100644 --- a/lua/snacks/picker/actions.lua +++ b/lua/snacks/picker/actions.lua @@ -350,6 +350,11 @@ function M.git_branch_del(picker, item) return end + local ok, choice = pcall(vim.fn.confirm, ("Delete branch %q?"):format(branch), "&Yes\n&Cancel") + if not ok or choice == 0 or choice == 2 then -- 0 for / and 2 for Cancel + return + end + -- Proceed with deletion Snacks.picker.util.cmd({ "git", "branch", "-d", branch }, function() Snacks.notify("Deleted Branch `" .. branch .. "`", { title = "Snacks Picker" }) From 4ec7621ff5449c9c51af8c26668bf1c8e8a651a8 Mon Sep 17 00:00:00 2001 From: Ian Liu Date: Wed, 5 Feb 2025 12:59:17 -0800 Subject: [PATCH 2/2] update: using picker select --- lua/snacks/picker/actions.lua | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/lua/snacks/picker/actions.lua b/lua/snacks/picker/actions.lua index 805ae66df..13d00d9f0 100644 --- a/lua/snacks/picker/actions.lua +++ b/lua/snacks/picker/actions.lua @@ -350,19 +350,18 @@ function M.git_branch_del(picker, item) return end - local ok, choice = pcall(vim.fn.confirm, ("Delete branch %q?"):format(branch), "&Yes\n&Cancel") - if not ok or choice == 0 or choice == 2 then -- 0 for / and 2 for Cancel - return - end - - -- Proceed with deletion - Snacks.picker.util.cmd({ "git", "branch", "-d", branch }, function() - Snacks.notify("Deleted Branch `" .. branch .. "`", { title = "Snacks Picker" }) - vim.cmd.checktime() - picker.list:set_selected() - picker.list:set_target() - picker:find() - end, { cwd = picker:cwd() }) + Snacks.picker.select({ "Yes", "No" }, { prompt = ("Delete branch %q?"):format(branch) }, function(_, idx) + if idx == 1 then + -- Proceed with deletion + Snacks.picker.util.cmd({ "git", "branch", "-d", branch }, function() + Snacks.notify("Deleted Branch `" .. branch .. "`", { title = "Snacks Picker" }) + vim.cmd.checktime() + picker.list:set_selected() + picker.list:set_target() + picker:find() + end, { cwd = picker:cwd() }) + end + end) end, { cwd = picker:cwd() }) end