This repository has been archived on 2024-05-17. You can view files and clone it, but cannot push or open issues or pull requests.
neovim/modules/gitsigns-nvim.nix

61 lines
1.8 KiB
Nix
Raw Normal View History

2024-04-20 23:05:33 +03:00
{ nix2lua, vim, lib, ... }:
with nix2lua.lib;
2024-04-21 11:46:13 +03:00
let
defaultKeymaps = [
2024-04-20 23:05:33 +03:00
{ mode = "n"; bind = "]h"; command = raw "next_hunk"; }
{ mode = "n"; bind = "[h"; command = raw "prev_hunk"; }
{ mode = "n"; bind = "<leader>gs"; command = raw "gs.stage_hunk"; }
{ mode = "n"; bind = "<leader>gr"; command = raw "gs.reset_hunk"; }
{ mode = "n"; bind = "<leader>gu"; command = raw "gs.undo_stage_hunk"; }
{ mode = "n"; bind = "<leader>gp"; command = raw "gs.preview_hunk"; }
{ mode = "n"; bind = "<leader>gb"; command = lambda0 (call "gs.blame_line" { full = true; }); }
{ mode = "n"; bind = "<leader>gd"; command = raw "gs.diffthis"; }
{ mode = "n"; bind = "<leader>gD"; command = lambda0 (call "gs.diffthis" "~"); }
{ mode = "n"; bind = "<leader>gtb"; command = raw "gs.toggle_current_line_blame"; }
{ mode = "n"; bind = "<leader>gtd"; command = raw "gs.toggle_deleted"; }
2024-04-21 11:46:13 +03:00
];
in
{ configs ? { }
, keymaps ? defaultKeymaps
, extraKeymaps ? [ ]
2024-04-20 23:05:33 +03:00
}:
let
2024-04-21 11:46:13 +03:00
bufferedKeymaps = map
(args: lib.recursiveUpdate args { opts.buffer = var "bufnr"; })
(keymaps ++ extraKeymaps);
2024-04-20 23:05:33 +03:00
in
{
gitsigns-nvim = [
(local (func "on_attach" [ "bufnr" ] (
[
(local (set "gs" (var "package.loaded.gitsigns")))
(local (func0 "next_hunk"
(ifelse (var "vim.wo.diff")
(call1 "vim.cmd.normal" [ "]h" (nf "bang" true) ])
(call1 "gs.nav_hunk" "next")
)
))
(local (func0 "prev_hunk"
(ifelse (var "vim.wo.diff")
(call1 "vim.cmd.normal" [ "[h" (nf "bang" true) ])
(call1 "gs.nav_hunk" "prev"))
))
]
++ map vim.keymap.set bufferedKeymaps
)))
(pipe1
(require "gitsigns")
(call "setup" (configs // {
on_attach = var "on_attach";
}))
)
];
}