nvim-config/lua/plugins/neotree.lua

91 lines
2.8 KiB
Lua
Raw Permalink Normal View History

2024-05-16 22:11:48 +00:00
local is_neotree_focused = function()
-- Get our current buffer number
local bufnr = vim.api.nvim_get_current_buf and vim.api.nvim_get_current_buf() or vim.fn.bufnr()
-- Get all the available sources in neo-tree
for _, source in ipairs(require("neo-tree").config.sources) do
-- Get each sources state
local state = require("neo-tree.sources.manager").get_state(source)
-- Check if the source has a state, if the state has a buffer and if the buffer is our current buffer
if state and state.bufnr and state.bufnr == bufnr then
return true
end
end
return false
end
local function is_neotree_open()
local manager = require("neo-tree.sources.manager")
local renderer = require("neo-tree.ui.renderer")
local success, state = pcall(manager.get_state, "filesystem")
if not success then
return false
end
local window_exists = renderer.window_exists(state)
return window_exists
end
-- If the tree is currently open and focused, then close it. If it's not open, or it's open
-- but not currently focused, it is made focused.
-- Effectively prevents the need to close and re-open it to gain focus of the tree.
local function toggle()
local cmd = require("neo-tree.command")
if is_neotree_open() and is_neotree_focused() then
cmd.execute({
action = "close",
})
else
cmd.execute({
action = "focus",
source = "filesystem",
position = "left",
})
end
end
2024-04-30 10:24:23 +00:00
return {
"nvim-neo-tree/neo-tree.nvim",
branch = "v3.x",
dependencies = {
2024-05-16 22:11:48 +00:00
"nvim-lua/plenary.nvim",
"nvim-tree/nvim-web-devicons",
"MunifTanjim/nui.nvim",
2024-04-30 10:24:23 +00:00
},
2024-05-16 22:11:48 +00:00
config = function()
vim.keymap.set("n", "<C-h>", toggle, {})
2024-05-19 10:57:25 +00:00
require("neo-tree").setup({
filesystem = {
filtered_items = {
visible = true,
hide_dotfiles = false,
hide_gitignored = true,
never_show = {
".git",
".mypy_cache",
"__pycache__",
},
2024-05-19 10:57:25 +00:00
},
},
2024-05-19 13:21:44 +00:00
default_component_configs = {
git_status = {
symbols = {
-- Change type
added = "A",
modified = "M",
deleted = "D",
renamed = "R",
-- Status type
untracked = "U",
ignored = "X",
unstaged = "U",
staged = "S",
conflict = "",
},
},
},
2024-05-19 10:57:25 +00:00
})
2024-05-16 22:11:48 +00:00
end,
2024-04-30 10:24:23 +00:00
}