From 36ff700b1a5bfa2dc35d15355bf34c154d2db1d6 Mon Sep 17 00:00:00 2001 From: Oscar Wallberg Date: Mon, 14 Apr 2025 00:38:33 +0200 Subject: [PATCH] feat(neo-tree): use trash for deletions --- lua/plugins/neo-tree.lua | 45 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/lua/plugins/neo-tree.lua b/lua/plugins/neo-tree.lua index 883f9b6..3175334 100644 --- a/lua/plugins/neo-tree.lua +++ b/lua/plugins/neo-tree.lua @@ -97,6 +97,51 @@ return { enabled = true, }, hijack_netrw_behavior = "disabled", + commands = { + -- over write default 'delete' command to 'trash'. + delete = function(state) + local inputs = require("neo-tree.ui.inputs") + local path = state.tree:get_node().path + local msg = "Send to trash?" + inputs.confirm(msg, function(confirmed) + if not confirmed then + return + end + + vim.fn.system({ "gio trash", vim.fn.fnameescape(path) }) + require("neo-tree.sources.manager").refresh(state.name) + end) + end, + + -- over write default 'delete_visual' command to 'trash' x n. + delete_visual = function(state, selected_nodes) + local inputs = require("neo-tree.ui.inputs") + + -- get table items count + function GetTableLen(tbl) + local len = 0 + for n in pairs(tbl) do + len = len + 1 + end + return len + end + + local count = GetTableLen(selected_nodes) + local msg = "Send " .. count .. " files to trash?" + inputs.confirm(msg, function(confirmed) + if not confirmed then + return + end + for _, node in ipairs(selected_nodes) do + vim.fn.system({ + "gio trash", + vim.fn.fnameescape(node.path), + }) + end + require("neo-tree.sources.manager").refresh(state.name) + end) + end, + }, }, }, init = function()