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

53 lines
1.6 KiB
Nix
Raw Normal View History

2023-02-06 00:44:38 +01:00
{
config,
lib,
...
}:
with lib;
with builtins; let
cfg = config.vim.terminal.toggleterm;
2023-04-24 13:16:43 +02:00
toggleKey = "<c-t>";
2023-02-06 00:44:38 +01:00
in {
config = mkIf cfg.enable {
vim.startPlugins = [
"toggleterm-nvim"
];
2023-04-24 13:16:43 +02: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
},
})
''
+ optionalString cfg.lazygit.enable ''
local terminal = require 'toggleterm.terminal'
local lazygit = terminal.Terminal:new({
cmd = "lazygit",
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-02-06 00:44:38 +01:00
end
2023-04-24 13:16:43 +02:00
})
vim.keymap.set( 'n', [[<leader>gg]], function() lazygit:toggle() end, {silent = true, noremap = true})
'');
2023-02-06 00:44:38 +01:00
};
}