Skip to content

feat(trash): add synchronized trash support for windows #2335

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3 changes: 1 addition & 2 deletions doc/nvim-tree-lua.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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*
Expand Down Expand Up @@ -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
Expand Down
10 changes: 7 additions & 3 deletions lua/nvim-tree/actions/fs/trash.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down