toggleterm: lazy load

This commit is contained in:
Ching Pei Yang 2024-09-30 21:58:54 +02:00 committed by Ching Pei Yang
parent 6c92f6cec5
commit bb2b3ff225
No known key found for this signature in database
GPG key ID: 062FBBCE1D0C5DD9

View file

@ -4,38 +4,31 @@
... ...
}: let }: let
inherit (builtins) toJSON; inherit (builtins) toJSON;
inherit (lib.lists) optionals; inherit (lib.strings) optionalString;
inherit (lib.modules) mkIf mkMerge; inherit (lib.modules) mkIf;
inherit (lib.meta) getExe; inherit (lib.meta) getExe;
inherit (lib.nvim.binds) mkBinding; inherit (lib.nvim.binds) mkLznBinding;
inherit (lib.nvim.dag) entryAnywhere entryAfter;
inherit (lib.nvim.lua) toLuaObject;
cfg = config.vim.terminal.toggleterm; cfg = config.vim.terminal.toggleterm;
lazygitMapDesc = "Open lazygit [toggleterm]";
in { in {
config = mkMerge [ config = mkIf cfg.enable {
(
mkIf cfg.enable {
vim = { vim = {
startPlugins = [ lazy.plugins = [
"toggleterm-nvim"
];
maps.normal = mkBinding cfg.mappings.open "<Cmd>execute v:count . \"ToggleTerm\"<CR>" "Toggle terminal";
pluginRC.toggleterm = entryAnywhere ''
require("toggleterm").setup(${toLuaObject cfg.setupOpts})
'';
};
}
)
(
mkIf (cfg.enable && cfg.lazygit.enable)
{ {
vim.startPlugins = optionals (cfg.lazygit.package != null) [ package = "toggleterm-nvim";
cfg.lazygit.package cmd = ["ToggleTerm" "ToggleTermSendCurrentLine" "ToggleTermSendVisualLines" "ToggleTermSendVisualSelection" "ToggleTermSetName" "ToggleTermToggleAll"];
keys = [
(mkLznBinding ["n"] cfg.mappings.open "<Cmd>execute v:count . \"ToggleTerm\"<CR>" "Toggle terminal")
{
key = cfg.lazygit.mappings.open;
desc = lazygitMapDesc;
}
]; ];
vim.pluginRC.toggleterm-lazygit = entryAfter ["toggleterm"] ''
setupModule = "toggleterm";
inherit (cfg) setupOpts;
after = optionalString cfg.lazygit.enable ''
local terminal = require 'toggleterm.terminal' local terminal = require 'toggleterm.terminal'
local lazygit = terminal.Terminal:new({ local lazygit = terminal.Terminal:new({
cmd = '${ cmd = '${
@ -50,9 +43,10 @@ in {
end end
}) })
vim.keymap.set('n', ${toJSON cfg.lazygit.mappings.open}, function() lazygit:toggle() end, {silent = true, noremap = true, desc = 'Open lazygit [toggleterm]'}) vim.keymap.set('n', ${toJSON cfg.lazygit.mappings.open}, function() lazygit:toggle() end, {silent = true, noremap = true, desc = '${lazygitMapDesc}'})
''; '';
} }
)
]; ];
};
};
} }