Some checks failed
Detach Plugins / check (FlyGrep.vim) (push) Has been cancelled
Detach Plugins / check (GitHub.vim) (push) Has been cancelled
Detach Plugins / check (JavaUnit.vim) (push) Has been cancelled
Detach Plugins / check (SourceCounter.vim) (push) Has been cancelled
Detach Plugins / check (cpicker.nvim) (push) Has been cancelled
Detach Plugins / check (dein-ui.vim) (push) Has been cancelled
Detach Plugins / check (git.vim) (push) Has been cancelled
Detach Plugins / check (iedit.vim) (push) Has been cancelled
Detach Plugins / check (scrollbar.vim) (push) Has been cancelled
Detach Plugins / check (vim-chat) (push) Has been cancelled
Detach Plugins / check (vim-cheat) (push) Has been cancelled
Detach Plugins / check (vim-todo) (push) Has been cancelled
Detach Plugins / check (xmake.vim) (push) Has been cancelled
test / Linux (nvim, nightly) (push) Has been cancelled
test / Linux (nvim, v0.3.8) (push) Has been cancelled
test / Linux (nvim, v0.4.0) (push) Has been cancelled
test / Linux (nvim, v0.4.2) (push) Has been cancelled
test / Linux (nvim, v0.4.3) (push) Has been cancelled
test / Linux (nvim, v0.4.4) (push) Has been cancelled
test / Linux (nvim, v0.5.0) (push) Has been cancelled
test / Linux (nvim, v0.5.1) (push) Has been cancelled
test / Linux (nvim, v0.6.0) (push) Has been cancelled
test / Linux (nvim, v0.6.1) (push) Has been cancelled
test / Linux (nvim, v0.7.0) (push) Has been cancelled
test / Linux (nvim, v0.7.2) (push) Has been cancelled
test / Linux (nvim, v0.8.0) (push) Has been cancelled
test / Linux (nvim, v0.8.1) (push) Has been cancelled
test / Linux (nvim, v0.8.2) (push) Has been cancelled
test / Linux (nvim, v0.8.3) (push) Has been cancelled
test / Linux (nvim, v0.9.0) (push) Has been cancelled
test / Linux (nvim, v0.9.1) (push) Has been cancelled
test / Linux (true, vim, v7.4.052) (push) Has been cancelled
test / Linux (true, vim, v7.4.1689) (push) Has been cancelled
test / Linux (true, vim, v7.4.629) (push) Has been cancelled
test / Linux (true, vim, v8.0.0027) (push) Has been cancelled
test / Linux (true, vim, v8.0.0183) (push) Has been cancelled
test / Linux (vim, nightly) (push) Has been cancelled
test / Linux (vim, v8.0.0184) (push) Has been cancelled
test / Linux (vim, v8.0.1453) (push) Has been cancelled
test / Linux (vim, v8.1.2269) (push) Has been cancelled
test / Linux (vim, v8.2.2434) (push) Has been cancelled
test / Linux (vim, v8.2.3995) (push) Has been cancelled
test / Windows (nvim, nightly) (push) Has been cancelled
test / Windows (nvim, v0.3.8) (push) Has been cancelled
test / Windows (nvim, v0.4.2) (push) Has been cancelled
test / Windows (nvim, v0.4.3) (push) Has been cancelled
test / Windows (nvim, v0.4.4) (push) Has been cancelled
test / Windows (nvim, v0.5.0) (push) Has been cancelled
test / Windows (nvim, v0.5.1) (push) Has been cancelled
test / Windows (nvim, v0.6.0) (push) Has been cancelled
test / Windows (nvim, v0.6.1) (push) Has been cancelled
test / Windows (nvim, v0.7.0) (push) Has been cancelled
test / Windows (nvim, v0.7.2) (push) Has been cancelled
test / Windows (nvim, v0.8.0) (push) Has been cancelled
test / Windows (nvim, v0.8.1) (push) Has been cancelled
test / Windows (nvim, v0.8.2) (push) Has been cancelled
test / Windows (nvim, v0.8.3) (push) Has been cancelled
test / Windows (nvim, v0.9.0) (push) Has been cancelled
test / Windows (nvim, v0.9.1) (push) Has been cancelled
test / Windows (vim, nightly) (push) Has been cancelled
test / Windows (vim, v7.4.1185) (push) Has been cancelled
test / Windows (vim, v7.4.1689) (push) Has been cancelled
test / Windows (vim, v8.0.0027) (push) Has been cancelled
test / Windows (vim, v8.0.1453) (push) Has been cancelled
test / Windows (vim, v8.1.2269) (push) Has been cancelled
test / Windows (vim, v8.2.2434) (push) Has been cancelled
test / Windows (vim, v8.2.3995) (push) Has been cancelled
docker / docker (push) Has been cancelled
mirror / check (coding) (push) Has been cancelled
mirror / check (gitee) (push) Has been cancelled
mirror / check (gitlab) (push) Has been cancelled
91 lines
2.2 KiB
Lua
91 lines
2.2 KiB
Lua
local a = vim.api
|
|
|
|
local M = {
|
|
config = {
|
|
is_windows = vim.fn.has "win32" == 1 or vim.fn.has "win32unix" == 1,
|
|
is_macos = vim.fn.has "mac" == 1 or vim.fn.has "macunix" == 1,
|
|
is_unix = vim.fn.has "unix" == 1,
|
|
},
|
|
}
|
|
|
|
local utils = require "nvim-tree.utils"
|
|
local events = require "nvim-tree.events"
|
|
|
|
local function clear_buffer(absolute_path)
|
|
local bufs = vim.fn.getbufinfo { bufloaded = 1, buflisted = 1 }
|
|
for _, buf in pairs(bufs) do
|
|
if buf.name == absolute_path then
|
|
if buf.hidden == 0 and #bufs > 1 then
|
|
local winnr = a.nvim_get_current_win()
|
|
a.nvim_set_current_win(buf.windows[1])
|
|
vim.cmd ":bn"
|
|
a.nvim_set_current_win(winnr)
|
|
end
|
|
vim.api.nvim_buf_delete(buf.bufnr, {})
|
|
return
|
|
end
|
|
end
|
|
end
|
|
|
|
function M.fn(node)
|
|
if node.name == ".." then
|
|
return
|
|
end
|
|
|
|
-- configs
|
|
if M.config.is_unix then
|
|
if M.config.trash.cmd == nil then
|
|
M.config.trash.cmd = "trash"
|
|
end
|
|
if M.config.trash.require_confirm == nil then
|
|
M.config.trash.require_confirm = true
|
|
end
|
|
else
|
|
utils.warn "Trash is currently a UNIX only feature!"
|
|
return
|
|
end
|
|
|
|
-- trashes a path (file or folder)
|
|
local function trash_path(on_exit)
|
|
vim.fn.jobstart(M.config.trash.cmd .. ' "' .. node.absolute_path .. '"', {
|
|
detach = true,
|
|
on_exit = on_exit,
|
|
})
|
|
end
|
|
|
|
local is_confirmed = true
|
|
|
|
-- confirmation prompt
|
|
if M.config.trash.require_confirm then
|
|
is_confirmed = false
|
|
print("Trash " .. node.name .. " ? y/n")
|
|
local ans = utils.get_user_input_char()
|
|
if ans:match "^y" then
|
|
is_confirmed = true
|
|
end
|
|
utils.clear_prompt()
|
|
end
|
|
|
|
-- trashing
|
|
if is_confirmed then
|
|
if node.nodes ~= nil and not node.link_to then
|
|
trash_path(function()
|
|
events._dispatch_folder_removed(node.absolute_path)
|
|
require("nvim-tree.actions.reloaders").reload_explorer()
|
|
end)
|
|
else
|
|
trash_path(function()
|
|
events._dispatch_file_removed(node.absolute_path)
|
|
clear_buffer(node.absolute_path)
|
|
require("nvim-tree.actions.reloaders").reload_explorer()
|
|
end)
|
|
end
|
|
end
|
|
end
|
|
|
|
function M.setup(opts)
|
|
M.config.trash = opts or {}
|
|
end
|
|
|
|
return M
|