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

59 lines
1.6 KiB
Nix
Raw Permalink Normal View History

2023-02-05 23:44:38 +00:00
{
config,
lib,
...
}: let
inherit (builtins) toJSON;
inherit (lib.lists) optionals;
inherit (lib.modules) mkIf mkMerge;
inherit (lib.meta) getExe;
inherit (lib.nvim.binds) mkBinding;
inherit (lib.nvim.dag) entryAnywhere entryAfter;
2024-03-09 13:55:44 +00:00
inherit (lib.nvim.lua) toLuaObject;
2023-02-05 23:44:38 +00:00
cfg = config.vim.terminal.toggleterm;
in {
2023-04-27 10:41:59 +00:00
config = mkMerge [
2023-04-27 10:52:34 +00:00
(
mkIf cfg.enable {
vim = {
startPlugins = [
"toggleterm-nvim"
];
2023-05-02 22:24:34 +00:00
maps.normal = mkBinding cfg.mappings.open "<Cmd>execute v:count . \"ToggleTerm\"<CR>" "Toggle terminal";
2023-02-05 23:44:38 +00:00
pluginRC.toggleterm = entryAnywhere ''
2024-03-09 13:55:44 +00:00
require("toggleterm").setup(${toLuaObject cfg.setupOpts})
'';
};
2023-04-27 10:41:59 +00:00
}
)
(
mkIf (cfg.enable && cfg.lazygit.enable)
{
vim.startPlugins = optionals (cfg.lazygit.package != null) [
2023-04-27 10:52:34 +00:00
cfg.lazygit.package
];
vim.pluginRC.toggleterm-lazygit = entryAfter ["toggleterm"] ''
2023-04-27 10:41:59 +00:00
local terminal = require 'toggleterm.terminal'
local lazygit = terminal.Terminal:new({
2023-04-27 10:52:34 +00:00
cmd = '${
if (cfg.lazygit.package != null)
then getExe cfg.lazygit.package
else "lazygit"
}',
2023-04-27 10:41:59 +00:00
direction = '${cfg.lazygit.direction}',
hidden = true,
on_open = function(term)
vim.cmd("startinsert!")
2023-04-24 11:16:43 +00:00
end
2023-04-27 10:41:59 +00:00
})
2023-04-11 12:38:27 +00:00
vim.keymap.set('n', ${toJSON cfg.lazygit.mappings.open}, function() lazygit:toggle() end, {silent = true, noremap = true, desc = 'Open lazygit [toggleterm]'})
2023-04-27 10:41:59 +00:00
'';
}
)
];
2023-02-05 23:44:38 +00:00
}