feat: neo-tree.nvim

This commit is contained in:
punkfairie 2024-12-01 11:05:41 -08:00
parent 1757b0b11f
commit 904e29db71
Signed by: punkfairie
GPG key ID: A509E8F77FB9D696
4 changed files with 136 additions and 0 deletions

View file

@ -48,6 +48,9 @@ with final.pkgs.lib; let
lualine-nvim
noice-nvim
indent-blankline-nvim
# Editor
neo-tree-nvim
];
extraPackages = with pkgs; [

View file

@ -14,5 +14,7 @@ return {
added = '',
modified = '',
removed = '',
unstaged = '󰄱',
staged = '󰱒',
},
}

View file

@ -0,0 +1,5 @@
local req = require('lib.marleyvim').localRequire('plugins.editor')
return {
req('neo-tree-nvim'),
}

View file

@ -0,0 +1,126 @@
---@param root? boolean
---@param grouped? boolean
local function make_toggle_mapping(root, grouped)
root = root or false
grouped = grouped or false
local lhs = grouped and '<LEADER>fe' or '<LEADER>e'
lhs = root and lhs or (lhs:gsub('%l$', string.upper))
return {
lhs,
function()
require('neo-tree.command').execute({
toggle = true,
dir = root and (MarleyVim.root()) or (vim.uv.cwd()),
})
end,
desc = 'Explorer (' .. (root and 'root' or 'cwd') .. ')',
}
end
return {
'neo-tree.nvim',
cmd = 'Neotree',
keys = {
make_toggle_mapping(true, true), -- root / grouped
make_toggle_mapping(false, true), -- cwd / grouped
make_toggle_mapping(true, false), -- root / non-grouped
make_toggle_mapping(false, false), -- cwd / non-grouped
{
'<LEADER>ge',
function()
require('neo-tree.command').execute({
source = 'git_status',
toggle = true,
})
end,
desc = 'Git explorer',
},
{
'<LEADER>be',
function()
require('neo-tree.command').execute({
source = 'buffers',
toggle = true,
})
end,
desc = 'Buffer explorer',
},
},
before = function()
require('lz.n').trigger_load({ 'plenary.nvim', 'mini.icons', 'nui.nvim' })
end,
after = function()
local icons = require('icons')
local events = require('neo-tree.events')
for _, type in ipairs({ 'Error', 'Warn', 'Info', 'Hint' }) do
vim.fn.sign_define(
'DiagnosticSign' .. type,
{ text = icons.diagnostics[type], texthl = 'DiagnosticSign' .. type }
)
end
local function on_move(data)
Snacks.rename.on_rename_file(data.source, data.destination)
end
require('neo-tree').setup({
close_if_last_window = true,
sources = { 'filesystem', 'buffers', 'git_status' },
open_files_do_not_replace_types = {
'terminal',
'Trouble',
'trouble',
'qf',
'Outline',
},
filesystem = {
bind_to_cwd = false,
follow_current_file = { enabled = true },
use_libuv_file_watcher = true,
filtered_items = {
visible = true,
hide_dotfiles = false,
},
},
window = {
mappings = {
['l'] = 'open',
['h'] = 'close_node',
['<SPACE>'] = 'none',
['Y'] = {
function(state)
local node = state.tree:get_node()
local path = node:get_id()
vim.fn.setreg('+', path, 'c')
end,
desc = 'copy path to clipboard',
},
['P'] = { 'toggle_preview', config = { use_float = false } },
},
},
default_component_configs = {
indent = {
with_expanders = true,
expanders_collapsed = '',
expander_expanded = '',
expander_highlight = 'NeoTreeExpander',
},
git_status = {
symbols = {
unstaged = icons.git.unstaged,
staged = icons.git.staged,
},
},
},
event_handlers = {
{ event = events.FILE_MOVED, handler = on_move },
{ event = events.FILE_RENAMED, handler = on_move },
},
})
end,
}