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
This commit is contained in:
Alexander Courtis 2023-08-13 12:18:06 +10:00 committed by GitHub
parent 904f95cd9d
commit 0a54dcb76b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 17 deletions

View File

@ -1148,8 +1148,10 @@ Configuration options for trashing.
*nvim-tree.trash.cmd* *nvim-tree.trash.cmd*
The command used to trash items (must be installed on your system). The command used to trash items (must be installed on your system).
The default is shipped with glib2 which is a common linux package. The default `"gio trash"` is shipped with glib2 which is a common linux package.
Type: `string`, Default: `"gio trash"` macOS default `"trash"` requires the homebrew package `trash`
Windows default `"trash"` requires `trash-cli` or similar
Type: `string`, Default: `"gio trash"` or `"trash"`
*nvim-tree.actions* *nvim-tree.actions*
Configuration for various actions. Configuration for various actions.
@ -2291,7 +2293,6 @@ vim.keymap.set("n", "<leader>ms", require("nvim-tree.api").marks.navigate.select
10. OS SPECIFIC RESTRICTIONS *nvim-tree-os-specific* 10. OS SPECIFIC RESTRICTIONS *nvim-tree-os-specific*
macOS macOS
- Trash is unavailable
- Rename to different case is not possible when using a case insensitive file - Rename to different case is not possible when using a case insensitive file
system. system.

View File

@ -669,6 +669,13 @@ local function validate_options(conf)
end end
end end
--- Apply OS specific localisations to DEFAULT_OPTS
local function localise_default_opts()
if utils.is_macos or utils.is_windows then
DEFAULT_OPTS.trash.cmd = "trash"
end
end
function M.purge_all_state() function M.purge_all_state()
require("nvim-tree.watcher").purge_watchers() require("nvim-tree.watcher").purge_watchers()
view.close_all_tabs() view.close_all_tabs()
@ -687,6 +694,8 @@ function M.setup(conf)
M.init_root = vim.fn.getcwd() M.init_root = vim.fn.getcwd()
localise_default_opts()
legacy.migrate_legacy_options(conf or {}) legacy.migrate_legacy_options(conf or {})
validate_options(conf) validate_options(conf)

View File

@ -29,22 +29,9 @@ function M.fn(node)
return return
end end
-- configs
if utils.is_unix or utils.is_windows then
if M.config.trash.cmd == nil then
M.config.trash.cmd = "trash"
end
if M.config.ui.confirm.trash == nil then
M.config.ui.confirm.trash = true
end
else
notify.warn "Trash is currently a UNIX only feature!"
return
end
local binary = M.config.trash.cmd:gsub(" .*$", "") local binary = M.config.trash.cmd:gsub(" .*$", "")
if vim.fn.executable(binary) == 0 then if vim.fn.executable(binary) == 0 then
notify.warn(binary .. " is not executable.") notify.warn(string.format("trash.cmd '%s' is not an executable.", M.config.trash.cmd))
return return
end end