From 6d1c8972ea9bafd299fb90fc121881555f426ad1 Mon Sep 17 00:00:00 2001 From: MasterUgwae Date: Mon, 13 Jan 2025 18:05:03 +0000 Subject: [PATCH] Adding neotree to lua/user --- lua/user/neo-tree.lua | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 lua/user/neo-tree.lua diff --git a/lua/user/neo-tree.lua b/lua/user/neo-tree.lua new file mode 100644 index 00000000..fa94452e --- /dev/null +++ b/lua/user/neo-tree.lua @@ -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 +