Skip to content

fix: trash.cmd defaults to 'trash' on macos #2336

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

Merged
merged 6 commits into from
Aug 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions doc/nvim-tree-lua.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1148,8 +1148,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.
Type: `string`, Default: `"gio trash"`
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.
Expand Down Expand Up @@ -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*

macOS
- Trash is unavailable
- Rename to different case is not possible when using a case insensitive file
system.

Expand Down
9 changes: 9 additions & 0 deletions lua/nvim-tree.lua
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,13 @@ local function validate_options(conf)
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"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't that be gio trash?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is where I get confused. I was under the impression that gio would put the files in ~/.local/share/Trash/files which is not recognised by macos.

Perhaps we should just update the doc, removing "Trash is unavailable" and noting the available homebrew options for macos users.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it might be time for me to use https://github.com/sickcodes/Docker-OSX

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, we found that neither trash nor gio comes preinstalled on macOS so it's best to do what you said, which is to warn the users that D is not available unless you install trash from homebrew. We shouldn't use gio trash on macOS as it moves the file to a different location than ~/.Trash which is where the Bin icon is pointing to.

end
end

function M.purge_all_state()
require("nvim-tree.watcher").purge_watchers()
view.close_all_tabs()
Expand All @@ -687,6 +694,8 @@ function M.setup(conf)

M.init_root = vim.fn.getcwd()

localise_default_opts()

legacy.migrate_legacy_options(conf or {})

validate_options(conf)
Expand Down
15 changes: 1 addition & 14 deletions lua/nvim-tree/actions/fs/trash.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,9 @@ 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(binary .. " is not executable.")
notify.warn(string.format("trash.cmd '%s' is not an executable.", M.config.trash.cmd))
return
end

Expand Down