feat(neo-tree): use trash for deletions
This commit is contained in:
@@ -97,6 +97,51 @@ return {
|
|||||||
enabled = true,
|
enabled = true,
|
||||||
},
|
},
|
||||||
hijack_netrw_behavior = "disabled",
|
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()
|
init = function()
|
||||||
|
|||||||
Reference in New Issue
Block a user