From e22b2a81f43e50708f2d08e24aaf67c3db659a89 Mon Sep 17 00:00:00 2001 From: Alexander Courtis Date: Mon, 24 Jul 2023 10:06:03 +1000 Subject: [PATCH 1/4] fix: trash.cmd defaults to 'trash' on macos --- doc/nvim-tree-lua.txt | 6 +++--- lua/nvim-tree.lua | 9 +++++++++ lua/nvim-tree/actions/fs/trash.lua | 2 +- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/doc/nvim-tree-lua.txt b/doc/nvim-tree-lua.txt index cbb3421526c..037068ef9e2 100644 --- a/doc/nvim-tree-lua.txt +++ b/doc/nvim-tree-lua.txt @@ -1147,9 +1147,10 @@ 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"` + The default `"gio trash"` is shipped with glib2 which is a common linux package. + The macOS default `"trash"` is part of the base operating system. + Type: `string`, Default: `"gio trash"` or `"trash"` *nvim-tree.actions* Configuration for various actions. @@ -2288,7 +2289,6 @@ vim.keymap.set("n", "ms", require("nvim-tree.api").marks.navigate.select 10. OS SPECIFIC RESTRICTIONS *nvim-tree-os-specific* macOS -- Trash is unavailable - Rename to different case is not possible when using a case insensitive file system. diff --git a/lua/nvim-tree.lua b/lua/nvim-tree.lua index fc4cb1144aa..3cdcf163040 100644 --- a/lua/nvim-tree.lua +++ b/lua/nvim-tree.lua @@ -663,6 +663,13 @@ local function validate_options(conf) end end +--- Apply OS specific localisations to DEFAULT_OPTS +local function localise_default_opts() + if utils.is_macos then + DEFAULT_OPTS.trash.cmd = "trash" + end +end + function M.purge_all_state() require("nvim-tree.watcher").purge_watchers() view.close_all_tabs() @@ -681,6 +688,8 @@ function M.setup(conf) M.init_root = vim.fn.getcwd() + localise_default_opts() + legacy.migrate_legacy_options(conf or {}) validate_options(conf) diff --git a/lua/nvim-tree/actions/fs/trash.lua b/lua/nvim-tree/actions/fs/trash.lua index 954165ea2ad..e3f2a53a4d4 100644 --- a/lua/nvim-tree/actions/fs/trash.lua +++ b/lua/nvim-tree/actions/fs/trash.lua @@ -44,7 +44,7 @@ function M.fn(node) local binary = M.config.trash.cmd:gsub(" .*$", "") if vim.fn.executable(binary) == 0 then - notify.warn(binary .. " is not executable.") + notify.warn(string.format("trash.cmd '%s' is not available.", M.config.trash.cmd)) return end From fdcd03059251ce0b7032ab5995e02d532a720d12 Mon Sep 17 00:00:00 2001 From: Alexander Courtis Date: Sun, 6 Aug 2023 10:17:39 +1000 Subject: [PATCH 2/4] fix: macOS and windows default trash commands, allow trash on all OS --- doc/nvim-tree-lua.txt | 6 +++--- lua/nvim-tree.lua | 2 ++ lua/nvim-tree/actions/fs/trash.lua | 13 ------------- 3 files changed, 5 insertions(+), 16 deletions(-) diff --git a/doc/nvim-tree-lua.txt b/doc/nvim-tree-lua.txt index bcb9e0dc242..af8f7906a08 100644 --- a/doc/nvim-tree-lua.txt +++ b/doc/nvim-tree-lua.txt @@ -1149,9 +1149,9 @@ Configuration options for trashing. *nvim-tree.trash.cmd* The command used to trash items (must be installed on your system). The default `"gio trash"` is shipped with glib2 which is a common linux package. - The default `"gio trash"` is shipped with glib2 which is a common linux package. - The macOS default `"trash"` is part of the base operating system. - Type: `string`, Default: `"gio trash"` or `"trash"` + macOS default `"trash"` requires the homebrew package `trash` + Windows default `"???"` requires TODO @linrongbin16 + Type: `string`, Default: `"gio trash"` or `"trash"` or `"TODO @linrongbin16"` *nvim-tree.actions* Configuration for various actions. diff --git a/lua/nvim-tree.lua b/lua/nvim-tree.lua index 4baf2684269..c757f38bb9e 100644 --- a/lua/nvim-tree.lua +++ b/lua/nvim-tree.lua @@ -673,6 +673,8 @@ end local function localise_default_opts() if utils.is_macos then DEFAULT_OPTS.trash.cmd = "trash" + elseif utils.is_windows then + DEFAULT_OPTS.trash.cmd = "TODO @linrongbin16" end end diff --git a/lua/nvim-tree/actions/fs/trash.lua b/lua/nvim-tree/actions/fs/trash.lua index 635db8ea555..76d5bed8414 100644 --- a/lua/nvim-tree/actions/fs/trash.lua +++ b/lua/nvim-tree/actions/fs/trash.lua @@ -29,19 +29,6 @@ function M.fn(node) return 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(" .*$", "") if vim.fn.executable(binary) == 0 then notify.warn(string.format("trash.cmd '%s' is not available.", M.config.trash.cmd)) From c7db901d379c36561f0573bc5ef4ef9aabadfd50 Mon Sep 17 00:00:00 2001 From: Alexander Courtis Date: Sun, 6 Aug 2023 16:48:17 +1000 Subject: [PATCH 3/4] fix: windows default trash command doc --- doc/nvim-tree-lua.txt | 8 ++++---- lua/nvim-tree.lua | 4 +--- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/doc/nvim-tree-lua.txt b/doc/nvim-tree-lua.txt index d56ac807acc..37136524b1c 100644 --- a/doc/nvim-tree-lua.txt +++ b/doc/nvim-tree-lua.txt @@ -1148,10 +1148,10 @@ Configuration options for trashing. *nvim-tree.trash.cmd* The command used to trash items (must be installed on your system). - The default `"gio trash"` is shipped with glib2 which is a common linux package. - macOS default `"trash"` requires the homebrew package `trash` - Windows default `"???"` requires TODO @linrongbin16 - Type: `string`, Default: `"gio trash"` or `"trash"` or `"TODO @linrongbin16"` + The default `"gio trash"` is shipped with glib2 which is a common linux package. + 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* Configuration for various actions. diff --git a/lua/nvim-tree.lua b/lua/nvim-tree.lua index c757f38bb9e..f1164a62175 100644 --- a/lua/nvim-tree.lua +++ b/lua/nvim-tree.lua @@ -671,10 +671,8 @@ end --- Apply OS specific localisations to DEFAULT_OPTS local function localise_default_opts() - if utils.is_macos then + if utils.is_macos or utils.is_windows then DEFAULT_OPTS.trash.cmd = "trash" - elseif utils.is_windows then - DEFAULT_OPTS.trash.cmd = "TODO @linrongbin16" end end From 04ea7065e3daea38fbc18bb21a14d830abe94348 Mon Sep 17 00:00:00 2001 From: Alexander Courtis Date: Sun, 13 Aug 2023 12:14:45 +1000 Subject: [PATCH 4/4] fix: trash.cmd message --- lua/nvim-tree/actions/fs/trash.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/nvim-tree/actions/fs/trash.lua b/lua/nvim-tree/actions/fs/trash.lua index 76d5bed8414..00124108ef7 100644 --- a/lua/nvim-tree/actions/fs/trash.lua +++ b/lua/nvim-tree/actions/fs/trash.lua @@ -31,7 +31,7 @@ function M.fn(node) local binary = M.config.trash.cmd:gsub(" .*$", "") if vim.fn.executable(binary) == 0 then - notify.warn(string.format("trash.cmd '%s' is not available.", M.config.trash.cmd)) + notify.warn(string.format("trash.cmd '%s' is not an executable.", M.config.trash.cmd)) return end