From b34b174c680b7be511694c5050064449e7ee4124 Mon Sep 17 00:00:00 2001 From: matt1432 Date: Sun, 22 Dec 2024 03:20:05 -0500 Subject: [PATCH] refactor(nvim): update git nix code --- homeManagerModules/neovim/git/default.nix | 58 ++++++++++++++--------- 1 file changed, 36 insertions(+), 22 deletions(-) diff --git a/homeManagerModules/neovim/git/default.nix b/homeManagerModules/neovim/git/default.nix index b39a62a6..b046ea5b 100644 --- a/homeManagerModules/neovim/git/default.nix +++ b/homeManagerModules/neovim/git/default.nix @@ -1,27 +1,41 @@ -{pkgs, ...}: { - programs.neovim.plugins = [ - pkgs.vimPlugins.fugitive +{ + config, + lib, + pkgs, + ... +}: let + inherit (lib) mkIf; - { - plugin = pkgs.vimPlugins.gitsigns-nvim; - type = "lua"; - config = - # lua - '' - local gitsigns = require("gitsigns"); + cfg = config.programs.neovim; +in { + config = mkIf cfg.enable { + programs.neovim.plugins = [ + pkgs.vimPlugins.fugitive - local function visual_stage() - local first_line = vim.fn.line('v'); - local last_line = vim.fn.getpos('.')[2]; - gitsigns.stage_hunk({ first_line, last_line }); - end + { + plugin = pkgs.vimPlugins.gitsigns-nvim; + type = "lua"; + config = + # lua + '' + local gitsigns = require("gitsigns"); - vim.keymap.set("v", "gs", function() - visual_stage() - end); + local function visual_stage() + local first_line = vim.fn.line('v'); + local last_line = vim.fn.getpos('.')[2]; + gitsigns.stage_hunk({ first_line, last_line }); + end - gitsigns.setup(); - ''; - } - ]; + vim.keymap.set("v", "gs", function() + visual_stage() + end); + + gitsigns.setup(); + ''; + } + ]; + }; + + # For accurate stack trace + _file = ./default.nix; }