From 24b631f3430b39373d77edc455abbe6dca36a5e2 Mon Sep 17 00:00:00 2001 From: Ching Pei Yang Date: Mon, 24 Apr 2023 13:16:43 +0200 Subject: [PATCH] feat: lazygit integration --- modules/terminal/toggleterm/config.nix | 54 ++++++++++++++-------- modules/terminal/toggleterm/toggleterm.nix | 8 ++++ 2 files changed, 43 insertions(+), 19 deletions(-) diff --git a/modules/terminal/toggleterm/config.nix b/modules/terminal/toggleterm/config.nix index 9e98bb1..40e037a 100644 --- a/modules/terminal/toggleterm/config.nix +++ b/modules/terminal/toggleterm/config.nix @@ -6,31 +6,47 @@ with lib; with builtins; let cfg = config.vim.terminal.toggleterm; + toggleKey = ""; in { config = mkIf cfg.enable { vim.startPlugins = [ "toggleterm-nvim" ]; - vim.luaConfigRC.toggleterm = nvim.dag.entryAnywhere '' - require("toggleterm").setup({ - open_mapping = [[]], - 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 + 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}) end - end, - winbar = { - enabled = '${toString cfg.enable_winbar}', - name_formatter = function(term) -- term: Terminal - return term.name - end - }, - }) - ''; + }) + + vim.keymap.set( 'n', [[gg]], function() lazygit:toggle() end, {silent = true, noremap = true}) + ''); }; } diff --git a/modules/terminal/toggleterm/toggleterm.nix b/modules/terminal/toggleterm/toggleterm.nix index e2ed940..a3e5a42 100644 --- a/modules/terminal/toggleterm/toggleterm.nix +++ b/modules/terminal/toggleterm/toggleterm.nix @@ -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"; + }; + }; }; }