nvf/modules/plugins/terminal/toggleterm/config.nix

53 lines
1.6 KiB
Nix
Raw Normal View History

2023-02-05 23:44:38 +00:00
{
config,
lib,
...
}: let
inherit (builtins) toJSON;
2024-09-30 19:58:54 +00:00
inherit (lib.strings) optionalString;
inherit (lib.modules) mkIf;
inherit (lib.meta) getExe;
2024-09-30 19:58:54 +00:00
inherit (lib.nvim.binds) mkLznBinding;
2023-02-05 23:44:38 +00:00
cfg = config.vim.terminal.toggleterm;
2024-09-30 19:58:54 +00:00
lazygitMapDesc = "Open lazygit [toggleterm]";
2023-02-05 23:44:38 +00:00
in {
2024-09-30 19:58:54 +00:00
config = mkIf cfg.enable {
vim = {
lazy.plugins = [
{
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;
}
];
2023-05-02 22:24:34 +00:00
2024-09-30 19:58:54 +00:00
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
})
2023-02-05 23:44:38 +00:00
2024-09-30 19:58:54 +00:00
vim.keymap.set('n', ${toJSON cfg.lazygit.mappings.open}, function() lazygit:toggle() end, {silent = true, noremap = true, desc = '${lazygitMapDesc}'})
'';
2024-09-30 19:58:54 +00:00
}
];
};
};
2023-02-05 23:44:38 +00:00
}