Merge pull request #63 from horriblename/feat-lazygit

feat: lazygit integration
This commit is contained in:
NotAShelf 2023-04-28 13:43:44 +03:00 committed by GitHub
commit c1d3f37a3c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 79 additions and 26 deletions

View file

@ -7,4 +7,9 @@ Release notes for release 0.4
[[sec-release-0.4-changelog]]
=== Changelog
ttps://github.com/horriblename[horriblename]:
* Added `clangd` as alternative lsp for C/++.
* Added `toggleterm` integration for `lazygit`.

View file

@ -167,7 +167,10 @@ inputs: let
};
vim.terminal = {
toggleterm.enable = true;
toggleterm = {
enable = true;
lazygit.enable = true;
};
};
vim.ui = {

View file

@ -6,31 +6,62 @@
with lib;
with builtins; let
cfg = config.vim.terminal.toggleterm;
toggleKey = "<c-t>";
in {
config = mkIf cfg.enable {
vim.startPlugins = [
"toggleterm-nvim"
];
config = mkMerge [
(
mkIf cfg.enable {
vim.startPlugins = [
"toggleterm-nvim"
];
vim.luaConfigRC.toggleterm = nvim.dag.entryAnywhere ''
require("toggleterm").setup({
open_mapping = [[<c-t>]],
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
},
})
'';
};
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)
{
vim.startPlugins = lib.optionals (cfg.lazygit.package != null) [
cfg.lazygit.package
];
vim.luaConfigRC.toggleterm-lazygit = nvim.dag.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!")
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

@ -1,4 +1,5 @@
{
pkgs,
config,
lib,
...
@ -17,5 +18,18 @@ 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";
};
package = mkOption {
type = with types; nullOr package;
default = pkgs.lazygit;
description = "The package that should be used for lazygit. Setting it to null will attempt to use lazygit from your PATH";
};
};
};
}