feat: support custom trash commands (#110)
This commit is contained in:
parent
d27bfa1f37
commit
f535c1057c
4 changed files with 26 additions and 12 deletions
|
|
@ -153,8 +153,10 @@ require("oil").setup({
|
||||||
restore_win_options = true,
|
restore_win_options = true,
|
||||||
-- Skip the confirmation popup for simple operations
|
-- Skip the confirmation popup for simple operations
|
||||||
skip_confirm_for_simple_edits = false,
|
skip_confirm_for_simple_edits = false,
|
||||||
-- Deleted files will be removed with the `trash-put` command.
|
-- Deleted files will be removed with the trash_command (below).
|
||||||
delete_to_trash = false,
|
delete_to_trash = false,
|
||||||
|
-- Change this to customize the command used when deleting to trash
|
||||||
|
trash_command = "trash-put",
|
||||||
-- Selecting a new/moved/renamed file or directory will prompt you to save changes first
|
-- Selecting a new/moved/renamed file or directory will prompt you to save changes first
|
||||||
prompt_save_on_select_new_entry = true,
|
prompt_save_on_select_new_entry = true,
|
||||||
-- Keymaps in oil buffer. Can be any value that `vim.keymap.set` accepts OR a table of keymap
|
-- Keymaps in oil buffer. Can be any value that `vim.keymap.set` accepts OR a table of keymap
|
||||||
|
|
|
||||||
|
|
@ -44,8 +44,10 @@ OPTIONS *oil-option
|
||||||
restore_win_options = true,
|
restore_win_options = true,
|
||||||
-- Skip the confirmation popup for simple operations
|
-- Skip the confirmation popup for simple operations
|
||||||
skip_confirm_for_simple_edits = false,
|
skip_confirm_for_simple_edits = false,
|
||||||
-- Deleted files will be removed with the `trash-put` command.
|
-- Deleted files will be removed with the trash_command (below).
|
||||||
delete_to_trash = false,
|
delete_to_trash = false,
|
||||||
|
-- Change this to customize the command used when deleting to trash
|
||||||
|
trash_command = "trash-put",
|
||||||
-- Selecting a new/moved/renamed file or directory will prompt you to save changes first
|
-- Selecting a new/moved/renamed file or directory will prompt you to save changes first
|
||||||
prompt_save_on_select_new_entry = true,
|
prompt_save_on_select_new_entry = true,
|
||||||
-- Keymaps in oil buffer. Can be any value that `vim.keymap.set` accepts OR a table of keymap
|
-- Keymaps in oil buffer. Can be any value that `vim.keymap.set` accepts OR a table of keymap
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,11 @@
|
||||||
|
local config = require("oil.config")
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
M.recursive_delete = function(path, cb)
|
M.recursive_delete = function(path, cb)
|
||||||
local stdout = {}
|
local stdout = {}
|
||||||
local stderr = {}
|
local stderr = {}
|
||||||
local jid = vim.fn.jobstart({ "trash-put", path }, {
|
local cmd = vim.list_extend(vim.split(config.trash_command, "%s+"), { path })
|
||||||
|
local jid = vim.fn.jobstart(cmd, {
|
||||||
stdout_buffered = true,
|
stdout_buffered = true,
|
||||||
stderr_buffered = true,
|
stderr_buffered = true,
|
||||||
on_stdout = function(j, output)
|
on_stdout = function(j, output)
|
||||||
|
|
@ -28,9 +30,9 @@ M.recursive_delete = function(path, cb)
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
if jid == 0 then
|
if jid == 0 then
|
||||||
cb(string.format("Passed invalid argument '%s' to 'trash-put'", path))
|
cb(string.format("Passed invalid argument '%s' to '%s'", path, config.trash_command))
|
||||||
elseif jid == -1 then
|
elseif jid == -1 then
|
||||||
cb("'trash-put' is not executable")
|
cb(string.format("'%s' is not executable", config.trash_command))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -29,8 +29,10 @@ local default_config = {
|
||||||
restore_win_options = true,
|
restore_win_options = true,
|
||||||
-- Skip the confirmation popup for simple operations
|
-- Skip the confirmation popup for simple operations
|
||||||
skip_confirm_for_simple_edits = false,
|
skip_confirm_for_simple_edits = false,
|
||||||
-- Deleted files will be removed with the `trash-put` command.
|
-- Deleted files will be removed with the trash_command (below).
|
||||||
delete_to_trash = false,
|
delete_to_trash = false,
|
||||||
|
-- Change this to customize the command used when deleting to trash
|
||||||
|
trash_command = "trash-put",
|
||||||
-- Selecting a new/moved/renamed file or directory will prompt you to save changes first
|
-- Selecting a new/moved/renamed file or directory will prompt you to save changes first
|
||||||
prompt_save_on_select_new_entry = true,
|
prompt_save_on_select_new_entry = true,
|
||||||
-- Keymaps in oil buffer. Can be any value that `vim.keymap.set` accepts OR a table of keymap
|
-- Keymaps in oil buffer. Can be any value that `vim.keymap.set` accepts OR a table of keymap
|
||||||
|
|
@ -135,12 +137,18 @@ M.setup = function(opts)
|
||||||
new_conf.keymaps = opts.keymaps or {}
|
new_conf.keymaps = opts.keymaps or {}
|
||||||
end
|
end
|
||||||
|
|
||||||
if new_conf.delete_to_trash and vim.fn.executable("trash-put") == 0 then
|
if new_conf.delete_to_trash then
|
||||||
vim.notify(
|
local trash_bin = vim.split(new_conf.trash_command, " ")[1]
|
||||||
"oil.nvim: delete_to_trash is true, but trash-put executable not found.\nDeleted files will be permanently removed.",
|
if vim.fn.executable(trash_bin) == 0 then
|
||||||
vim.log.levels.WARN
|
vim.notify(
|
||||||
)
|
string.format(
|
||||||
new_conf.delete_to_trash = false
|
"oil.nvim: delete_to_trash is true, but '%s' executable not found.\nDeleted files will be permanently removed.",
|
||||||
|
new_conf.trash_command
|
||||||
|
),
|
||||||
|
vim.log.levels.WARN
|
||||||
|
)
|
||||||
|
new_conf.delete_to_trash = false
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
for k, v in pairs(new_conf) do
|
for k, v in pairs(new_conf) do
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue