Adding neotree to lua/user

This commit is contained in:
MasterUgwae 2025-01-13 18:05:03 +00:00
parent 78d0d9947f
commit 6d1c8972ea
1 changed files with 28 additions and 0 deletions

28
lua/user/neo-tree.lua Normal file
View File

@ -0,0 +1,28 @@
local M = {}
local find_buffer_by_type = function(type)
for _, buf in ipairs(vim.api.nvim_list_bufs()) do
local ft = vim.api.nvim_buf_get_option(buf, "filetype")
if ft == type then return buf end
end
return -1
end
local toggle_neotree = function(toggle_command)
if find_buffer_by_type "neo-tree" > 0 then
require("neo-tree.command").execute { action = "close" }
else
toggle_command()
end
end
function M.toggle_explorer_cwd()
toggle_neotree(function() require("neo-tree.command").execute { action = "focus", reveal = true, dir = vim.uv.cwd() } end)
end
function M.toggle_explorer_root()
toggle_neotree(function() require("neo-tree.command").execute { action = "focus", reveal = true } end)
end
return M