2023-07-30 08:40:46 +00:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
lib,
|
|
|
|
pkgs,
|
|
|
|
...
|
2023-11-07 00:50:27 +00:00
|
|
|
}: let
|
2024-02-26 05:05:23 +00:00
|
|
|
inherit (lib.strings) optionalString;
|
2024-11-04 15:50:50 +00:00
|
|
|
inherit (lib.modules) mkIf;
|
|
|
|
inherit (lib.nvim.binds) mkLznBinding;
|
2024-02-26 05:05:23 +00:00
|
|
|
inherit (lib.nvim.dag) entryAnywhere;
|
2024-04-07 15:31:06 +00:00
|
|
|
inherit (lib.nvim.binds) pushDownDefault;
|
2023-11-07 00:50:27 +00:00
|
|
|
|
2023-07-30 08:40:46 +00:00
|
|
|
cfg = config.vim.filetree.nvimTree;
|
2024-02-26 05:05:23 +00:00
|
|
|
self = import ./nvimtree.nix {inherit pkgs lib;};
|
|
|
|
inherit (self.options.vim.filetree.nvimTree) mappings;
|
2023-07-30 08:40:46 +00:00
|
|
|
in {
|
|
|
|
config = mkIf cfg.enable {
|
2024-11-04 15:50:50 +00:00
|
|
|
vim = {
|
|
|
|
binds.whichKey.register = pushDownDefault {
|
|
|
|
"<leader>t" = "+NvimTree";
|
|
|
|
};
|
2023-07-30 08:40:46 +00:00
|
|
|
|
2024-11-04 15:50:50 +00:00
|
|
|
lazy.plugins.nvim-tree-lua = {
|
|
|
|
package = "nvim-tree-lua";
|
|
|
|
setupModule = "nvim-tree";
|
|
|
|
inherit (cfg) setupOpts;
|
|
|
|
cmd = ["NvimTreeClipboard" "NvimTreeClose" "NvimTreeCollapse" "NvimTreeCollapseKeepBuffers" "NvimTreeFindFile" "NvimTreeFindFileToggle" "NvimTreeFocus" "NvimTreeHiTest" "NvimTreeOpen" "NvimTreeRefresh" "NvimTreeResize" "NvimTreeToggle"];
|
|
|
|
keys = [
|
|
|
|
(mkLznBinding ["n"] cfg.mappings.toggle ":NvimTreeToggle<cr>" mappings.toggle.description)
|
|
|
|
(mkLznBinding ["n"] cfg.mappings.refresh ":NvimTreeRefresh<cr>" mappings.refresh.description)
|
|
|
|
(mkLznBinding ["n"] cfg.mappings.findFile ":NvimTreeFindFile<cr>" mappings.findFile.description)
|
|
|
|
(mkLznBinding ["n"] cfg.mappings.focus ":NvimTreeFocus<cr>" mappings.focus.description)
|
|
|
|
];
|
|
|
|
};
|
2023-07-30 08:40:46 +00:00
|
|
|
|
2024-11-04 15:50:50 +00:00
|
|
|
pluginRC.nvimtreelua = entryAnywhere ''
|
|
|
|
${
|
|
|
|
optionalString cfg.setupOpts.disable_netrw ''
|
|
|
|
-- disable netrew completely
|
|
|
|
vim.g.loaded_netrw = 1
|
|
|
|
vim.g.loaded_netrwPlugin = 1
|
|
|
|
''
|
|
|
|
}
|
2023-07-30 08:40:46 +00:00
|
|
|
|
2024-11-04 15:50:50 +00:00
|
|
|
${
|
|
|
|
optionalString cfg.openOnSetup ''
|
|
|
|
${optionalString config.vim.lazy.enable ''require('lz.n').trigger_load("nvim-tree-lua")''}
|
|
|
|
-- autostart behaviour
|
|
|
|
-- Open on startup has been deprecated
|
|
|
|
-- see https://github.com/nvim-tree/nvim-tree.lua/wiki/Open-At-Startup
|
2023-07-30 13:00:18 +00:00
|
|
|
|
2024-11-04 15:50:50 +00:00
|
|
|
-- use a nix eval to dynamically insert the open on startup function
|
|
|
|
local function open_nvim_tree(data)
|
|
|
|
local IGNORED_FT = {
|
|
|
|
"markdown",
|
|
|
|
}
|
2023-07-30 13:00:18 +00:00
|
|
|
|
2024-11-04 15:50:50 +00:00
|
|
|
-- buffer is a real file on the disk
|
|
|
|
local real_file = vim.fn.filereadable(data.file) == 1
|
2023-07-30 13:00:18 +00:00
|
|
|
|
2024-11-12 02:04:33 +00:00
|
|
|
-- buffer is a directory
|
|
|
|
local directory = vim.fn.isdirectory(data.file) == 1
|
|
|
|
|
2024-11-04 15:50:50 +00:00
|
|
|
-- buffer is a [No Name]
|
|
|
|
local no_name = data.file == "" and vim.bo[data.buf].buftype == ""
|
2023-07-30 13:00:18 +00:00
|
|
|
|
2024-11-04 15:50:50 +00:00
|
|
|
-- &ft
|
|
|
|
local filetype = vim.bo[data.buf].ft
|
2023-07-30 13:00:18 +00:00
|
|
|
|
2024-11-04 15:50:50 +00:00
|
|
|
-- only files please
|
2024-11-12 02:04:33 +00:00
|
|
|
if not real_file and not directory and not no_name then
|
2024-11-04 15:50:50 +00:00
|
|
|
return
|
|
|
|
end
|
2023-07-30 13:00:18 +00:00
|
|
|
|
2024-11-04 15:50:50 +00:00
|
|
|
-- skip ignored filetypes
|
|
|
|
if vim.tbl_contains(IGNORED_FT, filetype) then
|
|
|
|
return
|
2024-11-12 02:04:33 +00:00
|
|
|
end
|
2023-07-30 13:00:18 +00:00
|
|
|
|
2024-11-12 02:04:33 +00:00
|
|
|
-- cd if buffer is a directory
|
|
|
|
if directory then
|
|
|
|
vim.cmd.cd(data.file)
|
|
|
|
end
|
2024-11-04 15:50:50 +00:00
|
|
|
-- open the tree but don't focus it
|
|
|
|
require("nvim-tree.api").tree.toggle({ focus = false })
|
2023-07-30 13:00:18 +00:00
|
|
|
end
|
|
|
|
|
2024-11-04 15:50:50 +00:00
|
|
|
-- function to automatically open the tree on VimEnter
|
|
|
|
vim.api.nvim_create_autocmd({ "VimEnter" }, { callback = open_nvim_tree })
|
|
|
|
''
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
};
|
2023-07-30 08:40:46 +00:00
|
|
|
};
|
|
|
|
}
|