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
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 {
config = mkIf cfg.enable {
vim = {
startPlugins = [
"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)
lazy.plugins = [
{
vim.startPlugins = optionals (cfg.lazygit.package != null) [
cfg.lazygit.package
package = "toggleterm-nvim";
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 lazygit = terminal.Terminal:new({
cmd = '${
@ -50,9 +43,10 @@ in {
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}'})
'';
}
)
];
};
};
}