Skip to content

Commit 0a54dcb

Browse files
authored
fix: trash.cmd defaults to 'trash' on macos and windows, document option (#2336)
* fix: trash.cmd defaults to 'trash' on macos * fix: macOS and windows default trash commands, allow trash on all OS * fix: windows default trash command doc * fix: trash.cmd message
1 parent 904f95c commit 0a54dcb

File tree

3 files changed

+14
-17
lines changed

3 files changed

+14
-17
lines changed

doc/nvim-tree-lua.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1148,8 +1148,10 @@ Configuration options for trashing.
11481148

11491149
*nvim-tree.trash.cmd*
11501150
The command used to trash items (must be installed on your system).
1151-
The default is shipped with glib2 which is a common linux package.
1152-
Type: `string`, Default: `"gio trash"`
1151+
The default `"gio trash"` is shipped with glib2 which is a common linux package.
1152+
macOS default `"trash"` requires the homebrew package `trash`
1153+
Windows default `"trash"` requires `trash-cli` or similar
1154+
Type: `string`, Default: `"gio trash"` or `"trash"`
11531155

11541156
*nvim-tree.actions*
11551157
Configuration for various actions.
@@ -2291,7 +2293,6 @@ vim.keymap.set("n", "<leader>ms", require("nvim-tree.api").marks.navigate.select
22912293
10. OS SPECIFIC RESTRICTIONS *nvim-tree-os-specific*
22922294

22932295
macOS
2294-
- Trash is unavailable
22952296
- Rename to different case is not possible when using a case insensitive file
22962297
system.
22972298

lua/nvim-tree.lua

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,13 @@ local function validate_options(conf)
669669
end
670670
end
671671

672+
--- Apply OS specific localisations to DEFAULT_OPTS
673+
local function localise_default_opts()
674+
if utils.is_macos or utils.is_windows then
675+
DEFAULT_OPTS.trash.cmd = "trash"
676+
end
677+
end
678+
672679
function M.purge_all_state()
673680
require("nvim-tree.watcher").purge_watchers()
674681
view.close_all_tabs()
@@ -687,6 +694,8 @@ function M.setup(conf)
687694

688695
M.init_root = vim.fn.getcwd()
689696

697+
localise_default_opts()
698+
690699
legacy.migrate_legacy_options(conf or {})
691700

692701
validate_options(conf)

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

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,9 @@ function M.fn(node)
2929
return
3030
end
3131

32-
-- configs
33-
if utils.is_unix or utils.is_windows then
34-
if M.config.trash.cmd == nil then
35-
M.config.trash.cmd = "trash"
36-
end
37-
if M.config.ui.confirm.trash == nil then
38-
M.config.ui.confirm.trash = true
39-
end
40-
else
41-
notify.warn "Trash is currently a UNIX only feature!"
42-
return
43-
end
44-
4532
local binary = M.config.trash.cmd:gsub(" .*$", "")
4633
if vim.fn.executable(binary) == 0 then
47-
notify.warn(binary .. " is not executable.")
34+
notify.warn(string.format("trash.cmd '%s' is not an executable.", M.config.trash.cmd))
4835
return
4936
end
5037

0 commit comments

Comments
 (0)