From 75c05742bc1f96d9606ee315b3c649973c4fb1cd Mon Sep 17 00:00:00 2001 From: linrongbin16 Date: Sat, 29 Jul 2023 15:34:47 +0800 Subject: [PATCH] feat(trash): add synchronized trash support for windows (#2335) * feat(trash): support 'trash' on Windows * feat(trash): need sync wait on Windows to avoid switch to other app from nvim process * doc: remove 'Only available for UNIX' * doc(trash): highlight 'Trash' on Windows is syncrhonized * doc(trash): highlight 'trash' on Windows is synchronized * doc(trash): remove dot * fix(trash): check for unix and windows * fix(trash): comment --------- Co-authored-by: Alexander Courtis --- doc/nvim-tree-lua.txt | 3 +-- lua/nvim-tree/actions/fs/trash.lua | 10 +++++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/doc/nvim-tree-lua.txt b/doc/nvim-tree-lua.txt index cbb34215..dd627333 100644 --- a/doc/nvim-tree-lua.txt +++ b/doc/nvim-tree-lua.txt @@ -1148,7 +1148,6 @@ Configuration options for trashing. *nvim-tree.trash.cmd* The command used to trash items (must be installed on your system). The default is shipped with glib2 which is a common linux package. - Only available for UNIX. Type: `string`, Default: `"gio trash"` *nvim-tree.actions* @@ -2293,7 +2292,7 @@ macOS system. Windows WSL and PowerShell -- Trash is unavailable +- Trash is synchronized - Executable file detection is disabled as this is non-performant and can freeze nvim - Some filesystem watcher error related to permissions will not be reported diff --git a/lua/nvim-tree/actions/fs/trash.lua b/lua/nvim-tree/actions/fs/trash.lua index 954165ea..523beb50 100644 --- a/lua/nvim-tree/actions/fs/trash.lua +++ b/lua/nvim-tree/actions/fs/trash.lua @@ -30,7 +30,7 @@ function M.fn(node) end -- configs - if utils.is_unix then + if utils.is_unix or utils.is_windows then if M.config.trash.cmd == nil then M.config.trash.cmd = "trash" end @@ -55,11 +55,15 @@ function M.fn(node) -- trashes a path (file or folder) local function trash_path(on_exit) - vim.fn.jobstart(M.config.trash.cmd .. ' "' .. node.absolute_path .. '"', { - detach = true, + local need_sync_wait = utils.is_windows + local job = vim.fn.jobstart(M.config.trash.cmd .. ' "' .. node.absolute_path .. '"', { + detach = not need_sync_wait, on_exit = on_exit, on_stderr = on_stderr, }) + if need_sync_wait then + vim.fn.jobwait { job } + end end local function do_trash()