From 72858986f9de019dc0e151c76090de29954081f0 Mon Sep 17 00:00:00 2001 From: Alexander Courtis Date: Wed, 29 Jun 2022 02:29:42 +1000 Subject: [PATCH] fix(#1366): warn when trash cmd missing (#1378) --- lua/nvim-tree/actions/trash.lua | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/lua/nvim-tree/actions/trash.lua b/lua/nvim-tree/actions/trash.lua index f2bc4e99..7a0d02ab 100644 --- a/lua/nvim-tree/actions/trash.lua +++ b/lua/nvim-tree/actions/trash.lua @@ -45,11 +45,17 @@ function M.fn(node) return end + local err_msg = "" + local function on_stderr(_, data) + err_msg = err_msg .. (data and table.concat(data, " ")) + end + -- trashes a path (file or folder) local function trash_path(on_exit) vim.fn.jobstart(M.config.trash.cmd .. ' "' .. node.absolute_path .. '"', { detach = true, on_exit = on_exit, + on_stderr = on_stderr, }) end @@ -69,14 +75,22 @@ function M.fn(node) -- trashing if is_confirmed then if node.nodes ~= nil and not node.link_to then - trash_path(function() + trash_path(function(_, rc) + if rc ~= 0 then + utils.warn("trash failed: " .. err_msg .. "; please see :help nvim-tree.trash") + return + end events._dispatch_folder_removed(node.absolute_path) if M.enable_reload then require("nvim-tree.actions.reloaders").reload_explorer() end end) else - trash_path(function() + trash_path(function(_, rc) + if rc ~= 0 then + utils.warn("trash failed: " .. err_msg .. "; please see :help nvim-tree.trash") + return + end events._dispatch_file_removed(node.absolute_path) clear_buffer(node.absolute_path) if M.enable_reload then