From 24b631f3430b39373d77edc455abbe6dca36a5e2 Mon Sep 17 00:00:00 2001 From: Ching Pei Yang Date: Mon, 24 Apr 2023 13:16:43 +0200 Subject: [PATCH 1/7] 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 9e98bb12..40e037a2 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 e2ed9401..a3e5a426 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"; + }; + }; }; } From f8ff3cd9fa161899922f1328f2f035248b574939 Mon Sep 17 00:00:00 2001 From: Ching Pei Yang Date: Thu, 27 Apr 2023 12:41:59 +0200 Subject: [PATCH 2/7] use separate dag for toggleterm --- modules/terminal/toggleterm/config.nix | 83 ++++++++++++++------------ 1 file changed, 45 insertions(+), 38 deletions(-) diff --git a/modules/terminal/toggleterm/config.nix b/modules/terminal/toggleterm/config.nix index 40e037a2..4bf85591 100644 --- a/modules/terminal/toggleterm/config.nix +++ b/modules/terminal/toggleterm/config.nix @@ -8,45 +8,52 @@ with builtins; let cfg = config.vim.terminal.toggleterm; toggleKey = ""; 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 = [[${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 + 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.luaConfigRC.toggleterm-lazygit = mkIf cfg.lazygit.enable nvim.dag.entryAfter ["toggleterm"] '' + 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 - }, - }) - '' - + 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', [[gg]], function() lazygit:toggle() end, {silent = true, noremap = true}) - ''); - }; + vim.keymap.set( 'n', [[gg]], function() lazygit:toggle() end, {silent = true, noremap = true}) + ''; + } + ) + ]; } From 2018cd7b2fc9aa927fa6295f91afc1133c823ccf Mon Sep 17 00:00:00 2001 From: Ching Pei Yang Date: Thu, 27 Apr 2023 12:52:34 +0200 Subject: [PATCH 3/7] (lazygit) add option `package` --- modules/terminal/toggleterm/config.nix | 14 +++++++++++--- modules/terminal/toggleterm/toggleterm.nix | 6 ++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/modules/terminal/toggleterm/config.nix b/modules/terminal/toggleterm/config.nix index 4bf85591..868dec4e 100644 --- a/modules/terminal/toggleterm/config.nix +++ b/modules/terminal/toggleterm/config.nix @@ -9,7 +9,8 @@ with builtins; let toggleKey = ""; in { config = mkMerge [ - (mkIf cfg.enable { + ( + mkIf cfg.enable { vim.startPlugins = [ "toggleterm-nvim" ]; @@ -39,10 +40,17 @@ in { ( mkIf (cfg.enable && cfg.lazygit.enable) { - vim.luaConfigRC.toggleterm-lazygit = mkIf cfg.lazygit.enable nvim.dag.entryAfter ["toggleterm"] '' + 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 = "lazygit", + cmd = '${ + if (cfg.lazygit.package != null) + then getExe cfg.lazygit.package + else "lazygit" + }', direction = '${cfg.lazygit.direction}', hidden = true, on_open = function(term) diff --git a/modules/terminal/toggleterm/toggleterm.nix b/modules/terminal/toggleterm/toggleterm.nix index a3e5a426..e304bf68 100644 --- a/modules/terminal/toggleterm/toggleterm.nix +++ b/modules/terminal/toggleterm/toggleterm.nix @@ -1,4 +1,5 @@ { + pkgs, config, lib, ... @@ -24,6 +25,11 @@ with builtins; { default = "float"; description = "Direction of the lazygit window"; }; + package = mkOption { + type = with types; nullOr package; + default = pkgs.lazygit; + description = "The package to use for lazygit, null means do not install automatically"; + }; }; }; } From 7afe92b8450d848e813def844a4ae474c6c463d5 Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Fri, 28 Apr 2023 08:59:35 +0300 Subject: [PATCH 4/7] dev: enable lazygit out of the box --- extra.nix | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/extra.nix b/extra.nix index fa1f4d96..df799587 100644 --- a/extra.nix +++ b/extra.nix @@ -167,7 +167,10 @@ inputs: let }; vim.terminal = { - toggleterm.enable = true; + toggleterm = { + enable = true; + lazygit.enable = true; + }; }; vim.ui = { From 132b93a633009a7eb4eb0bf3fa9aa603aee0a8db Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Fri, 28 Apr 2023 09:49:11 +0300 Subject: [PATCH 5/7] docs: update release notes with lazygit --- docs/release-notes/rl-0.4.adoc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/release-notes/rl-0.4.adoc b/docs/release-notes/rl-0.4.adoc index 6f35b5d2..ddf5f75b 100644 --- a/docs/release-notes/rl-0.4.adoc +++ b/docs/release-notes/rl-0.4.adoc @@ -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`. From 719db9906772d553422c3566041923012b0a8279 Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Fri, 28 Apr 2023 09:49:31 +0300 Subject: [PATCH 6/7] docs: clarify `lazygit.package` usage --- modules/terminal/toggleterm/toggleterm.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/terminal/toggleterm/toggleterm.nix b/modules/terminal/toggleterm/toggleterm.nix index e304bf68..09b03f25 100644 --- a/modules/terminal/toggleterm/toggleterm.nix +++ b/modules/terminal/toggleterm/toggleterm.nix @@ -28,7 +28,7 @@ with builtins; { package = mkOption { type = with types; nullOr package; default = pkgs.lazygit; - description = "The package to use for lazygit, null means do not install automatically"; + description = "The package that should be used for lazygit. Setting it to null will attempt to use lazygit from your PATH"; }; }; }; From c01f5bc2bc654dec52355f0f04c71953d8b89bd5 Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Fri, 28 Apr 2023 13:39:29 +0300 Subject: [PATCH 7/7] style: formatting --- extra.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extra.nix b/extra.nix index df799587..767d5dd6 100644 --- a/extra.nix +++ b/extra.nix @@ -170,7 +170,7 @@ inputs: let toggleterm = { enable = true; lazygit.enable = true; - }; + }; }; vim.ui = {