Merge branch 'main' into feature/custom-keybinds

This commit is contained in:
Michał 2023-05-03 00:18:25 +02:00 committed by GitHub
commit 933fa2a8ae
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
22 changed files with 190 additions and 130 deletions

View file

@ -6,33 +6,64 @@
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.maps.normal = mkBinding cfg.mappings.open "<Cmd>execute v:count . \"ToggleTerm\"<CR>" "Toggle terminal";
vim.luaConfigRC.toggleterm = nvim.dag.entryAnywhere ''
require("toggleterm").setup({
open_mapping = null,
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 = null,
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.maps.normal = mkBinding cfg.mappings.open "<Cmd>execute v:count . \"ToggleTerm\"<CR>" "Toggle terminal";
};
vim.keymap.set( 'n', [[<leader>gg]], function() lazygit:toggle() end, {silent = true, noremap = true})
'';
}
)
];
}

View file

@ -1,4 +1,5 @@
{
pkgs,
config,
lib,
...
@ -24,5 +25,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";
};
};
};
}