nvf/modules/terminal/toggleterm/config.nix

68 lines
2 KiB
Nix
Raw Normal View History

2023-02-05 23:44:38 +00:00
{
config,
lib,
...
}:
with lib;
with builtins; let
cfg = config.vim.terminal.toggleterm;
2023-04-24 11:16:43 +00:00
toggleKey = "<c-t>";
2023-02-05 23:44:38 +00:00
in {
2023-04-27 10:41:59 +00:00
config = mkMerge [
2023-04-27 10:52:34 +00:00
(
mkIf cfg.enable {
2023-04-27 10:41:59 +00:00
vim.startPlugins = [
"toggleterm-nvim"
];
2023-02-05 23:44:38 +00:00
2023-04-27 10:41:59 +00:00
vim.luaConfigRC.toggleterm = nvim.dag.entryAnywhere ''
require("toggleterm").setup({
open_mapping = [[${toggleKey}]],
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 10:52:34 +00:00
vim.startPlugins = lib.optionals (cfg.lazygit.package != null) [
cfg.lazygit.package
];
vim.luaConfigRC.toggleterm-lazygit = nvim.dag.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!")
vim.keymap.set( 't', [[${toggleKey}]], function() term:toggle() end, {silent = true, noremap = true, buffer = term.bufnr})
2023-04-24 11:16:43 +00:00
end
2023-04-27 10:41:59 +00:00
})
2023-04-24 11:16:43 +00:00
2023-04-27 10:41:59 +00:00
vim.keymap.set( 'n', [[<leader>gg]], function() lazygit:toggle() end, {silent = true, noremap = true})
'';
}
)
];
2023-02-05 23:44:38 +00:00
}