feat: lazygit integration

This commit is contained in:
Ching Pei Yang 2023-04-24 13:16:43 +02:00
parent 9e224d710c
commit 24b631f343
2 changed files with 43 additions and 19 deletions

View file

@ -6,15 +6,16 @@
with lib;
with builtins; let
cfg = config.vim.terminal.toggleterm;
toggleKey = "<c-t>";
in {
config = mkIf cfg.enable {
vim.startPlugins = [
"toggleterm-nvim"
];
vim.luaConfigRC.toggleterm = nvim.dag.entryAnywhere ''
vim.luaConfigRC.toggleterm = nvim.dag.entryAnywhere (''
require("toggleterm").setup({
open_mapping = [[<c-t>]],
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)
@ -31,6 +32,21 @@ in {
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})
end
})
vim.keymap.set( 'n', [[<leader>gg]], function() lazygit:toggle() end, {silent = true, noremap = true})
'');
};
}

View file

@ -17,5 +17,13 @@ with builtins; {
default = false;
description = "Enable winbar";
};
lazygit = {
enable = mkEnableOption "Enable LazyGit integration";
direction = mkOption {
type = types.enum ["horizontal" "vertical" "tab" "float"];
default = "float";
description = "Direction of the lazygit window";
};
};
};
}