1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
return {
{
"nvim-neo-tree/neo-tree.nvim",
branch = "v3.x",
dependencies = {
"nvim-lua/plenary.nvim",
"nvim-tree/nvim-web-devicons", -- not strictly required, but recommended
"MunifTanjim/nui.nvim",
{ "3rd/image.nvim", opts = {} }, -- Optional image support in preview window: See `# Preview Mode` for more information
},
lazy = false, -- neo-tree will lazily load itself
---@module "neo-tree"
---@type neotree.Config?
opts = {
filesystem = {
follow_current_file = { enabled = false },
commands = {
-- over write default 'delete' command to 'trash'.
delete = function(state)
if vim.fn.executable("trash") == 0 then
vim.api.nvim_echo({
{ "- Trash utility not installed. Make sure to install it first\n", nil },
{ "- In macOS run `brew install trash`\n", nil },
{ "- Or delete the `custom delete command` section in neo-tree", nil },
}, false, {})
return
end
local inputs = require("neo-tree.ui.inputs")
local path = state.tree:get_node().path
local msg = "Are you sure you want to trash " .. path
inputs.confirm(msg, function(confirmed)
if not confirmed then
return
end
vim.fn.system({ "trash", vim.fn.fnameescape(path) })
require("neo-tree.sources.manager").refresh(state.name)
end)
end,
-- Overwrite default 'delete_visual' command to 'trash' x n.
delete_visual = function(state, selected_nodes)
if vim.fn.executable("trash") == 0 then
vim.api.nvim_echo({
{ "- Trash utility not installed. Make sure to install it first\n", nil },
{ "- In macOS run `brew install trash`\n", nil },
{ "- Or delete the `custom delete command` section in neo-tree", nil },
}, false, {})
return
end
local inputs = require("neo-tree.ui.inputs")
-- Function to get the count of items in a table
local function GetTableLen(tbl)
local len = 0
for _ in pairs(tbl) do
len = len + 1
end
return len
end
local count = GetTableLen(selected_nodes)
local msg = "Are you sure you want to trash " .. count .. " files?"
inputs.confirm(msg, function(confirmed)
if not confirmed then
return
end
for _, node in ipairs(selected_nodes) do
vim.fn.system({ "trash", vim.fn.fnameescape(node.path) })
end
require("neo-tree.sources.manager").refresh(state.name)
end)
end,
},
},
},
keys = {
{ "<leader>e", false },
{ "<leader>E", false },
{
"<leader>en",
function()
local buf_name = vim.api.nvim_buf_get_name(0)
-- Function to check if NeoTree is open in any window
local function is_neo_tree_open()
for _, win in ipairs(vim.api.nvim_list_wins()) do
local buf = vim.api.nvim_win_get_buf(win)
if vim.bo[buf].filetype == "neo-tree" then
return true
end
end
return false
end
-- Check if the current file exists
if
vim.fn.filereadable(buf_name) == 1
or vim.fn.isdirectory(vim.fn.fnamemodify(buf_name, ":p:h")) == 1
then
if is_neo_tree_open() then
-- Close NeoTree if it's open
vim.cmd("Neotree close")
else
-- Open NeoTree and reveal the current file
vim.cmd("Neotree reveal")
end
else
-- If the file doesn't exist, execute the logic for <leader>R
require("neo-tree.command").execute({ toggle = true, dir = vim.uv.cwd() })
end
end,
desc = "Open neo-tree",
},
{
"<leader>eN",
function()
require("neo-tree.command").execute({ toggle = true, dir = vim.uv.cwd() })
end,
desc = "Open neo-tree (cwd)",
},
},
},
}
|