diff --git a/default.nix b/default.nix index caee21d..b6b1375 100644 --- a/default.nix +++ b/default.nix @@ -16,6 +16,7 @@ let plugins = callPlugins [ ./plugins/syntax + ./plugins/git ./plugins/explorer (import ./plugins/theme { inherit enableBarBar enableDevIcons; diff --git a/plugins/git/default.nix b/plugins/git/default.nix new file mode 100644 index 0000000..3c82ffc --- /dev/null +++ b/plugins/git/default.nix @@ -0,0 +1,7 @@ +{ gitsigns-nvim, ... }: + +{ + luaConfig = builtins.readFile ./gitsigns-nvim.lua; + + plugins = [ gitsigns-nvim ]; +} diff --git a/plugins/git/gitsigns-nvim.lua b/plugins/git/gitsigns-nvim.lua new file mode 100644 index 0000000..ff4d8b7 --- /dev/null +++ b/plugins/git/gitsigns-nvim.lua @@ -0,0 +1,52 @@ +function on_attach(bufnr) + local gs = package.loaded.gitsigns + + local function map(mode, l, r, opts) + opts = opts or {} + opts.buffer = bufnr + vim.keymap.set(mode, l, r, opts) + end + + -- Navigation + map("n", "]h", function() + if vim.wo.diff then + return "]h" + end + vim.schedule(function() + gs.next_hunk() + end) + return "" + end, { expr = true }) + + map("n", "[h", function() + if vim.wo.diff then + return "[h" + end + vim.schedule(function() + gs.prev_hunk() + end) + return "" + end, { expr = true }) + + -- Actions + map({ "n", "v" }, "gs", ":Gitsigns stage_hunk") + map({ "n", "v" }, "gr", ":Gitsigns reset_hunk") + map("n", "gu", gs.undo_stage_hunk) + map("n", "gp", gs.preview_hunk) + map("n", "gb", function() + gs.blame_line({ full = true }) + end) + map("n", "gtb", gs.toggle_current_line_blame) + map("n", "gd", gs.diffthis) + map("n", "gD", function() + gs.diffthis("~") + end) + + -- Text object + map({ "o", "x" }, "ih", ":Gitsigns select_hunk") +end + +-- See: https://github.com/lewis6991/gitsigns.nvim +require("gitsigns").setup({ + on_attach = on_attach, +})