2023-02-05 23:44:38 +00:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
lib,
|
|
|
|
...
|
2023-11-07 00:50:27 +00:00
|
|
|
}: let
|
2024-11-04 15:50:50 +00:00
|
|
|
inherit (lib.strings) optionalString;
|
|
|
|
inherit (lib.lists) optional;
|
|
|
|
inherit (lib.modules) mkIf;
|
2024-03-12 00:47:27 +00:00
|
|
|
inherit (lib.meta) getExe;
|
2024-11-04 15:50:50 +00:00
|
|
|
inherit (lib.nvim.binds) mkLznBinding;
|
2024-03-09 13:55:44 +00:00
|
|
|
inherit (lib.nvim.lua) toLuaObject;
|
2023-11-07 00:50:27 +00:00
|
|
|
|
2023-02-05 23:44:38 +00:00
|
|
|
cfg = config.vim.terminal.toggleterm;
|
2024-11-04 15:50:50 +00:00
|
|
|
lazygitMapDesc = "Open lazygit [toggleterm]";
|
2023-02-05 23:44:38 +00:00
|
|
|
in {
|
2024-11-04 15:50:50 +00:00
|
|
|
config = mkIf cfg.enable {
|
|
|
|
vim = {
|
|
|
|
lazy.plugins.toggleterm-nvim = {
|
|
|
|
package = "toggleterm-nvim";
|
|
|
|
cmd = ["ToggleTerm" "ToggleTermSendCurrentLine" "ToggleTermSendVisualLines" "ToggleTermSendVisualSelection" "ToggleTermSetName" "ToggleTermToggleAll"];
|
|
|
|
keys =
|
|
|
|
[(mkLznBinding ["n"] cfg.mappings.open "<Cmd>execute v:count . \"ToggleTerm\"<CR>" "Toggle terminal")]
|
|
|
|
++ optional cfg.lazygit.enable {
|
|
|
|
key = cfg.lazygit.mappings.open;
|
2024-11-11 00:06:09 +00:00
|
|
|
mode = "n";
|
2024-11-04 15:50:50 +00:00
|
|
|
desc = lazygitMapDesc;
|
|
|
|
};
|
2023-05-02 22:24:34 +00:00
|
|
|
|
2024-11-04 15:50:50 +00:00
|
|
|
setupModule = "toggleterm";
|
|
|
|
inherit (cfg) setupOpts;
|
|
|
|
after = optionalString cfg.lazygit.enable ''
|
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!")
|
2023-04-24 11:16:43 +00:00
|
|
|
end
|
2023-04-27 10:41:59 +00:00
|
|
|
})
|
2023-04-11 12:38:27 +00:00
|
|
|
|
2024-11-04 15:50:50 +00:00
|
|
|
vim.keymap.set('n', ${toLuaObject cfg.lazygit.mappings.open}, function() lazygit:toggle() end, {silent = true, noremap = true, desc = '${lazygitMapDesc}'})
|
2023-04-27 10:41:59 +00:00
|
|
|
'';
|
2024-11-04 15:50:50 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2023-02-05 23:44:38 +00:00
|
|
|
}
|