nvim-telescope / telescope-file-browser.nvim

File Browser extension for telescope.nvim
MIT License
1.68k stars 92 forks source link

[question] Custom command for `remove` action? #364

Closed fmorroni closed 6 months ago

fmorroni commented 6 months ago

What the title says. I want to change the remove action so that it uses the command trashy put instead of rm (or whatever it uses under the hood). That way the removed files don't get permanently deleted and instead go into the trash so I can restore them if I removed them by mistake. Is this currently posible? Another option would be to make a function that somehow gets the telescope selection files and manually executes the trashy command with the selected files as arguments. But I don't know how I can get the selected files as an object I can manipulate in a function.

jamestrew commented 6 months ago

See this issue on this topic here: https://github.com/nvim-telescope/telescope-file-browser.nvim/issues/169 It should be relatively straight forward if you know some lua. I can help with some the telescope specific parts if needed.

fmorroni commented 6 months ago

Hi thanks, totally missed that issue. I ended up replacing the original remove action like this:

require("telescope").setup({
  extensions = {
    file_browser = {
      attach_mappings = function()
        fb_actions.remove:replace(trashy_remove)
        return true
      end,
    },
  },
})

Where trashy_remove is a customized version of the original remove action found in https://github.com/nvim-telescope/telescope-file-browser.nvim/blob/8839e3f8070dfafa5b0c0e4652700298e7b872c4/lua/telescope/_extensions/file_browser/actions.lua#L483.