neovim-flake/modules/plugins/terminal/toggleterm/config.nix
diniamo a0197fe1bb treewide: migrate to pluginRC for correct DAG order
The "new" DAG order is as follows:
- (luaConfigPre)
- globalsScript
- basic
- theme
- pluginConfigs
- extraPluginConfigs
- mappings
- (luaConfigPost)
2024-07-18 10:25:58 +02:00

58 lines
1.6 KiB
Nix

{
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;
inherit (lib.nvim.lua) toLuaObject;
cfg = config.vim.terminal.toggleterm;
in {
config = mkMerge [
(
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)
{
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]'})
'';
}
)
];
}