From bb2b3ff225cf41c47ba66a91dba2f17d615d2eae Mon Sep 17 00:00:00 2001 From: Ching Pei Yang <59727193+horriblename@users.noreply.github.com> Date: Mon, 30 Sep 2024 21:58:54 +0200 Subject: [PATCH] toggleterm: lazy load --- .../plugins/terminal/toggleterm/config.nix | 80 +++++++++---------- 1 file changed, 37 insertions(+), 43 deletions(-) diff --git a/modules/plugins/terminal/toggleterm/config.nix b/modules/plugins/terminal/toggleterm/config.nix index 07851e4..b416748 100644 --- a/modules/plugins/terminal/toggleterm/config.nix +++ b/modules/plugins/terminal/toggleterm/config.nix @@ -4,55 +4,49 @@ ... }: let inherit (builtins) toJSON; - inherit (lib.lists) optionals; - inherit (lib.modules) mkIf mkMerge; + inherit (lib.strings) optionalString; + inherit (lib.modules) mkIf; inherit (lib.meta) getExe; - inherit (lib.nvim.binds) mkBinding; - inherit (lib.nvim.dag) entryAnywhere entryAfter; - inherit (lib.nvim.lua) toLuaObject; + inherit (lib.nvim.binds) mkLznBinding; cfg = config.vim.terminal.toggleterm; + lazygitMapDesc = "Open lazygit [toggleterm]"; in { - config = mkMerge [ - ( - mkIf cfg.enable { - vim = { - startPlugins = [ - "toggleterm-nvim" + config = mkIf cfg.enable { + vim = { + lazy.plugins = [ + { + package = "toggleterm-nvim"; + cmd = ["ToggleTerm" "ToggleTermSendCurrentLine" "ToggleTermSendVisualLines" "ToggleTermSendVisualSelection" "ToggleTermSetName" "ToggleTermToggleAll"]; + keys = [ + (mkLznBinding ["n"] cfg.mappings.open "execute v:count . \"ToggleTerm\"" "Toggle terminal") + { + key = cfg.lazygit.mappings.open; + desc = lazygitMapDesc; + } ]; - maps.normal = mkBinding cfg.mappings.open "execute v:count . \"ToggleTerm\"" "Toggle terminal"; + setupModule = "toggleterm"; + inherit (cfg) setupOpts; + after = optionalString cfg.lazygit.enable '' + local terminal = require 'toggleterm.terminal' + local lazygit = terminal.Terminal:new({ + cmd = '${ + if (cfg.lazygit.package != null) + then getExe cfg.lazygit.package + else "lazygit" + }', + direction = '${cfg.lazygit.direction}', + hidden = true, + on_open = function(term) + vim.cmd("startinsert!") + end + }) - pluginRC.toggleterm = entryAnywhere '' - require("toggleterm").setup(${toLuaObject cfg.setupOpts}) + vim.keymap.set('n', ${toJSON cfg.lazygit.mappings.open}, function() lazygit:toggle() end, {silent = true, noremap = true, desc = '${lazygitMapDesc}'}) ''; - }; - } - ) - ( - mkIf (cfg.enable && cfg.lazygit.enable) - { - vim.startPlugins = optionals (cfg.lazygit.package != null) [ - cfg.lazygit.package - ]; - vim.pluginRC.toggleterm-lazygit = entryAfter ["toggleterm"] '' - local terminal = require 'toggleterm.terminal' - local lazygit = terminal.Terminal:new({ - cmd = '${ - if (cfg.lazygit.package != null) - then getExe cfg.lazygit.package - else "lazygit" - }', - direction = '${cfg.lazygit.direction}', - hidden = true, - on_open = function(term) - vim.cmd("startinsert!") - end - }) - - vim.keymap.set('n', ${toJSON cfg.lazygit.mappings.open}, function() lazygit:toggle() end, {silent = true, noremap = true, desc = 'Open lazygit [toggleterm]'}) - ''; - } - ) - ]; + } + ]; + }; + }; }