|
|
|
vim.g.loaded_netrw = 1
|
|
|
|
vim.g.loaded_netrwPlugin = 1
|
|
|
|
vim.opt.termguicolors = true
|
|
|
|
|
|
|
|
local M = { "nvim-tree/nvim-tree.lua" }
|
|
|
|
|
|
|
|
M.tag = "nvim-tree-v1.9.0"
|
|
|
|
|
|
|
|
M.keys = {
|
|
|
|
{ "<leader>nt", ":NvimTreeToggle<CR>", desc = "toggle nvim tree" }
|
|
|
|
}
|
|
|
|
|
|
|
|
M.dependencies = {
|
|
|
|
-- https://github.com/nvim-tree/nvim-web-devicons
|
|
|
|
"nvim-tree/nvim-web-devicons", opts = {}
|
|
|
|
}
|
|
|
|
|
|
|
|
function M.config()
|
|
|
|
require("nvim-tree").setup()
|
|
|
|
vim.api.nvim_create_autocmd("WinClosed", {
|
|
|
|
nested = true,
|
|
|
|
callback = function()
|
|
|
|
M.handle_closed(tonumber(vim.fn.expand("<amatch>")))
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
|
|
|
function M.handle_closed(window)
|
|
|
|
local tab = vim.api.nvim_win_get_tabpage(window)
|
|
|
|
local buffer = vim.api.nvim_win_get_buf(window)
|
|
|
|
local info = vim.fn.getbufinfo(buffer)[1]
|
|
|
|
|
|
|
|
local function filter_window(w)
|
|
|
|
return w ~= window
|
|
|
|
end
|
|
|
|
|
|
|
|
local windows = vim.tbl_filter(filter_window, vim.api.nvim_tabpage_list_wins(tab))
|
|
|
|
local buffers = vim.tbl_map(vim.api.nvim_win_get_buf, windows)
|
|
|
|
|
|
|
|
if info.name:match(".*NvimTree_%d*$") then
|
|
|
|
if not vim.tbl_isempty(buffers) then
|
|
|
|
require("nvim-tree.api").tree.close()
|
|
|
|
end
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
if #buffers ~= 1 then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
local last_info = vim.fn.getbufinfo(buffers[1])[1]
|
|
|
|
if last_info.name:match(".*NvimTree_%d*$") then
|
|
|
|
vim.schedule(function()
|
|
|
|
if #vim.api.nvim_list_wins() == 1 then
|
|
|
|
vim.cmd "quit"
|
|
|
|
else
|
|
|
|
vim.api.nvim_win_close(windows[1], true)
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return M
|