Skip to content

Commit 75c0574

Browse files
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 <[email protected]>
1 parent c1466f9 commit 75c0574

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

doc/nvim-tree-lua.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1148,7 +1148,6 @@ Configuration options for trashing.
11481148
*nvim-tree.trash.cmd*
11491149
The command used to trash items (must be installed on your system).
11501150
The default is shipped with glib2 which is a common linux package.
1151-
Only available for UNIX.
11521151
Type: `string`, Default: `"gio trash"`
11531152

11541153
*nvim-tree.actions*
@@ -2293,7 +2292,7 @@ macOS
22932292
system.
22942293

22952294
Windows WSL and PowerShell
2296-
- Trash is unavailable
2295+
- Trash is synchronized
22972296
- Executable file detection is disabled as this is non-performant and can
22982297
freeze nvim
22992298
- Some filesystem watcher error related to permissions will not be reported

lua/nvim-tree/actions/fs/trash.lua

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ function M.fn(node)
3030
end
3131

3232
-- configs
33-
if utils.is_unix then
33+
if utils.is_unix or utils.is_windows then
3434
if M.config.trash.cmd == nil then
3535
M.config.trash.cmd = "trash"
3636
end
@@ -55,11 +55,15 @@ function M.fn(node)
5555

5656
-- trashes a path (file or folder)
5757
local function trash_path(on_exit)
58-
vim.fn.jobstart(M.config.trash.cmd .. ' "' .. node.absolute_path .. '"', {
59-
detach = true,
58+
local need_sync_wait = utils.is_windows
59+
local job = vim.fn.jobstart(M.config.trash.cmd .. ' "' .. node.absolute_path .. '"', {
60+
detach = not need_sync_wait,
6061
on_exit = on_exit,
6162
on_stderr = on_stderr,
6263
})
64+
if need_sync_wait then
65+
vim.fn.jobwait { job }
66+
end
6367
end
6468

6569
local function do_trash()

0 commit comments

Comments
 (0)