From 62b1e30e4987a453b5f4083853116ebc4cdff731 Mon Sep 17 00:00:00 2001 From: Ching Pei Yang Date: Fri, 8 Nov 2024 17:55:52 +0100 Subject: [PATCH] neo-tree: add hijack netrw --- modules/plugins/filetree/neo-tree/config.nix | 22 +++++++++++++++++++ .../plugins/filetree/neo-tree/neo-tree.nix | 10 ++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/modules/plugins/filetree/neo-tree/config.nix b/modules/plugins/filetree/neo-tree/config.nix index 13da035..53b8db2 100644 --- a/modules/plugins/filetree/neo-tree/config.nix +++ b/modules/plugins/filetree/neo-tree/config.nix @@ -4,6 +4,7 @@ ... }: let inherit (lib.modules) mkIf; + inherit (lib.strings) optionalString; cfg = config.vim.filetree.neo-tree; in { @@ -21,7 +22,28 @@ in { setupModule = "neo-tree"; inherit (cfg) setupOpts; + beforeAll = + optionalString (cfg.setupOpts.filesystem.hijack_netrw_behavior != "disabled") + # from https://github.com/nvim-neo-tree/neo-tree.nvim/discussions/1326 + '' + vim.api.nvim_create_autocmd("BufEnter", { + group = vim.api.nvim_create_augroup("load_neo_tree", {}), + desc = "Loads neo-tree when openning a directory", + callback = function(args) + local stats = vim.uv.fs_stat(args.file) + + if not stats or stats.type ~= "directory" then + return + end + + require("lz.n").trigger_load("neo-tree-nvim") + + return true + end, + }) + ''; cmd = ["Neotree"]; + event = []; }; visuals.nvimWebDevicons.enable = true; diff --git a/modules/plugins/filetree/neo-tree/neo-tree.nix b/modules/plugins/filetree/neo-tree/neo-tree.nix index b1ec260..29199d4 100644 --- a/modules/plugins/filetree/neo-tree/neo-tree.nix +++ b/modules/plugins/filetree/neo-tree/neo-tree.nix @@ -1,5 +1,5 @@ {lib, ...}: let - inherit (lib.types) bool str int submodule enum either listOf; + inherit (lib.types) bool str enum either listOf; inherit (lib.options) mkOption mkEnableOption literalExpression; inherit (lib.nvim.types) mkPluginSetupOption; in { @@ -150,6 +150,14 @@ in { A list of filetypes that should not be replaced when opening a file ''; }; + + filesystem = { + hijack_netrw_behavior = mkOption { + type = enum ["disabled" "open_default" "open_current"]; + default = "open_default"; + description = "Hijack Netrw behavior"; + }; + }; }; }; }