neovim-flake/modules/terminal/toggleterm/config.nix

68 lines
2 KiB
Nix
Raw Normal View History

2023-02-06 00:44:38 +01:00
{
config,
lib,
...
}: let
inherit (lib) mkMerge mkIf mkBinding nvim getExe;
2023-02-06 00:44:38 +01:00
cfg = config.vim.terminal.toggleterm;
in {
2023-04-27 12:41:59 +02:00
config = mkMerge [
2023-04-27 12:52:34 +02:00
(
mkIf cfg.enable {
2023-04-27 12:41:59 +02:00
vim.startPlugins = [
"toggleterm-nvim"
];
2023-05-03 00:24:34 +02:00
vim.maps.normal = mkBinding cfg.mappings.open "<Cmd>execute v:count . \"ToggleTerm\"<CR>" "Toggle terminal";
2023-02-06 00:44:38 +01:00
2023-04-27 12:41:59 +02:00
vim.luaConfigRC.toggleterm = nvim.dag.entryAnywhere ''
require("toggleterm").setup({
open_mapping = null,
2023-04-27 12:41:59 +02:00
direction = '${toString cfg.direction}',
-- TODO: this should probably be turned into a module that uses the lua function if and only if the user has not set it
size = function(term)
if term.direction == "horizontal" then
return 15
elseif term.direction == "vertical" then
return vim.o.columns * 0.4
end
end,
winbar = {
enabled = '${toString cfg.enable_winbar}',
name_formatter = function(term) -- term: Terminal
return term.name
end
},
})
'';
}
)
(
mkIf (cfg.enable && cfg.lazygit.enable)
{
2023-04-27 12:52:34 +02:00
vim.startPlugins = lib.optionals (cfg.lazygit.package != null) [
cfg.lazygit.package
];
vim.luaConfigRC.toggleterm-lazygit = nvim.dag.entryAfter ["toggleterm"] ''
2023-04-27 12:41:59 +02:00
local terminal = require 'toggleterm.terminal'
local lazygit = terminal.Terminal:new({
2023-04-27 12:52:34 +02:00
cmd = '${
if (cfg.lazygit.package != null)
then getExe cfg.lazygit.package
else "lazygit"
}',
2023-04-27 12:41:59 +02:00
direction = '${cfg.lazygit.direction}',
hidden = true,
on_open = function(term)
vim.cmd("startinsert!")
2023-04-24 13:16:43 +02:00
end
2023-04-27 12:41:59 +02:00
})
2023-04-11 14:38:27 +02:00
vim.keymap.set('n', ${builtins.toJSON cfg.lazygit.mappings.open}, function() lazygit:toggle() end, {silent = true, noremap = true, desc = 'Open lazygit [toggleterm]'})
2023-04-27 12:41:59 +02:00
'';
}
)
];
2023-02-06 00:44:38 +01:00
}