-
-
Notifications
You must be signed in to change notification settings - Fork 92
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
An option to trash files instead of removing them #169
Comments
I briefly looked into it and it's very OS-dependent (as eg there is no Instead, you can very easily implement your own solution if you know a little (pretty much only a tiny) bit of lua. Have a look at telescope-file-browser.nvim/lua/telescope/_extensions/file_browser/actions.lua Lines 283 to 314 in 4272c52
and then implement a function ala require "telescope".setup {
extensions = {
file_browser = {
mappings = {
["i"] = {
-- move selection(s) to where your trash bin is
["KEY"] = function(prompt_bufnr) ... end
}
}
}
}
}
The core idea is that rename a file/folder is essentially the same thing as moving it to the folder, that is, you change the original folder prefix to the trash prefix. |
If there is a clean proposal and PR to implement this, I'd very much consider it, but I'm generally quite happy with current scope of filesys operations of For the time being, closing. |
Thanks for the hints. I just rewrote my config in Lua the other day, had no experience with overwriting Telescope actions. There are also issues with duplicates and setting up original folders and deletion timestamps, so it's not as straightforward as just moving files. I ended up with the following implementation: require("telescope").setup({
extensions = {
file_browser = {
-- <...>
mappings = {
["i"] = {
-- Trash files instead of deleting them
["<A-d>"] = function(prompt_bufnr)
local action_state = require("telescope.actions.state")
local call = require("config.utils").call
local fb_utils = require("telescope._extensions.file_browser.utils")
-- Get the finder
local current_picker = action_state.get_current_picker(prompt_bufnr)
local finder = current_picker.finder
-- Get the selections
local selections = fb_utils.get_selected_files(prompt_bufnr, false)
if vim.tbl_isempty(selections) then
fb_utils.notify("actions.trash",
{ msg = "No selection to be trashed!", level = "WARN", quiet = finder.quiet })
return
end
-- Trash the selected files
local trashed = {}
for _, selection in ipairs(selections) do
local filename = selection.filename:sub(#selection:parent().filename + 2)
-- `trash-put` is from the `trash-cli` package
if call({ "trash-put", "--", selection:absolute() }) then
table.insert(trashed, filename)
end
end
-- Notify about operations
local message = ""
if not vim.tbl_isempty(trashed) then
message = message .. "Trashed: " .. table.concat(trashed, ", ")
end
fb_utils.notify("actions.trash", { msg = message, level = "INFO", quiet = finder.quiet })
-- Reset multi selection
current_picker:refresh(current_picker.finder, { reset_prompt = true })
end,
}
}
},
}
}) where -- Do a system call and check the status code
function call(cmd)
fn.system(cmd)
return vim.v.shell_error == 0
end |
I'm very glad to hear you've managed to whip up a solution that works for you! :) |
Is your feature request related to a problem? Please describe.
I would like to put files in the trash instead of removing them.
Describe the solution you'd like
A generic way to override the
remove
action (so I can change it to thetrash
command).Describe alternatives you've considered
A configuration flag.
The text was updated successfully, but these errors were encountered: