2023-07-30 10:40:46 +02:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
lib,
|
|
|
|
pkgs,
|
|
|
|
...
|
2023-11-07 01:50:27 +01:00
|
|
|
}: let
|
2024-08-03 14:46:05 +02:00
|
|
|
inherit (builtins) filter;
|
2024-02-26 06:05:23 +01:00
|
|
|
inherit (lib.strings) optionalString;
|
|
|
|
inherit (lib.modules) mkIf mkMerge;
|
|
|
|
inherit (lib.nvim.binds) mkBinding;
|
|
|
|
inherit (lib.nvim.dag) entryAnywhere;
|
2024-01-03 00:55:03 +01:00
|
|
|
inherit (lib.nvim.lua) toLuaObject;
|
2024-04-07 17:31:06 +02:00
|
|
|
inherit (lib.nvim.binds) pushDownDefault;
|
2023-11-07 01:50:27 +01:00
|
|
|
|
2023-07-30 10:40:46 +02:00
|
|
|
cfg = config.vim.filetree.nvimTree;
|
2024-02-26 06:05:23 +01:00
|
|
|
self = import ./nvimtree.nix {inherit pkgs lib;};
|
2024-08-03 14:46:05 +02:00
|
|
|
mkNormalBinding = lhs: rhs: desc: {
|
|
|
|
inherit lhs rhs desc;
|
|
|
|
mode = ["n"];
|
|
|
|
};
|
2024-02-26 06:05:23 +01:00
|
|
|
inherit (self.options.vim.filetree.nvimTree) mappings;
|
2023-07-30 10:40:46 +02:00
|
|
|
in {
|
|
|
|
config = mkIf cfg.enable {
|
2024-02-26 04:52:21 +01:00
|
|
|
vim.binds.whichKey.register = pushDownDefault {
|
2024-02-25 17:39:05 +01:00
|
|
|
"<leader>t" = "+NvimTree";
|
|
|
|
};
|
|
|
|
|
2024-07-24 13:23:53 +02:00
|
|
|
vim.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"];
|
2024-08-03 14:46:05 +02:00
|
|
|
|
|
|
|
keys = filter ({lhs, ...}: lhs != null) [
|
|
|
|
(mkNormalBinding cfg.mappings.toggle ":NvimTreeToggle<cr>" mappings.toggle.description)
|
|
|
|
(mkNormalBinding cfg.mappings.refresh ":NvimTreeRefresh<cr>" mappings.refresh.description)
|
|
|
|
(mkNormalBinding cfg.mappings.findFile ":NvimTreeFindFile<cr>" mappings.findFile.description)
|
|
|
|
(mkNormalBinding cfg.mappings.focus ":NvimTreeFocus<cr>" mappings.focus.description)
|
|
|
|
];
|
2024-07-24 13:23:53 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-07-20 10:30:48 +02:00
|
|
|
vim.pluginRC.nvimtreelua = entryAnywhere ''
|
2023-07-30 14:02:36 +02:00
|
|
|
${
|
2024-04-21 00:06:10 +02:00
|
|
|
optionalString cfg.setupOpts.disable_netrw ''
|
2023-07-30 15:00:18 +02:00
|
|
|
-- disable netrew completely
|
2023-07-30 10:40:46 +02:00
|
|
|
vim.g.loaded_netrw = 1
|
|
|
|
vim.g.loaded_netrwPlugin = 1
|
|
|
|
''
|
|
|
|
}
|
|
|
|
|
2023-07-30 15:00:18 +02:00
|
|
|
${
|
2024-02-26 06:05:23 +01:00
|
|
|
optionalString cfg.openOnSetup ''
|
|
|
|
-- autostart behaviour
|
2023-07-30 15:00:18 +02:00
|
|
|
-- Open on startup has been deprecated
|
|
|
|
-- see https://github.com/nvim-tree/nvim-tree.lua/wiki/Open-At-Startup
|
|
|
|
|
|
|
|
-- use a nix eval to dynamically insert the open on startup function
|
|
|
|
local function open_nvim_tree(data)
|
|
|
|
local IGNORED_FT = {
|
|
|
|
"markdown",
|
|
|
|
}
|
|
|
|
|
|
|
|
-- buffer is a real file on the disk
|
|
|
|
local real_file = vim.fn.filereadable(data.file) == 1
|
|
|
|
|
|
|
|
-- buffer is a [No Name]
|
|
|
|
local no_name = data.file == "" and vim.bo[data.buf].buftype == ""
|
|
|
|
|
|
|
|
-- &ft
|
|
|
|
local filetype = vim.bo[data.buf].ft
|
|
|
|
|
|
|
|
-- only files please
|
|
|
|
if not real_file and not no_name then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
-- skip ignored filetypes
|
|
|
|
if vim.tbl_contains(IGNORED_FT, filetype) then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
-- open the tree but don't focus it
|
|
|
|
require("nvim-tree.api").tree.toggle({ focus = false })
|
|
|
|
end
|
|
|
|
|
|
|
|
-- function to automatically open the tree on VimEnter
|
|
|
|
vim.api.nvim_create_autocmd({ "VimEnter" }, { callback = open_nvim_tree })
|
|
|
|
''
|
|
|
|
}
|
2023-07-30 14:02:36 +02:00
|
|
|
'';
|
2023-07-30 10:40:46 +02:00
|
|
|
};
|
|
|
|
}
|