From ce6193bb7b0cb97d8ed1385f14880604f05aa2ea Mon Sep 17 00:00:00 2001
From: Oliver Davies <oliver@oliverdavies.uk>
Date: Fri, 11 Aug 2023 00:25:15 +0100
Subject: [PATCH] feat(nvim): add fugitive keymaps

Add keymaps to open `git status` within Fugitive as well as push and
pull changes within a fugitive buffer.
---
 config/neovim/after/plugin/fugitive.lua | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)
 create mode 100644 config/neovim/after/plugin/fugitive.lua

diff --git a/config/neovim/after/plugin/fugitive.lua b/config/neovim/after/plugin/fugitive.lua
new file mode 100644
index 00000000..311cfc8d
--- /dev/null
+++ b/config/neovim/after/plugin/fugitive.lua
@@ -0,0 +1,22 @@
+vim.keymap.set("n", "<leader>gs", vim.cmd.Git)
+
+vim.api.nvim_create_autocmd("BufWinEnter", {
+  pattern = "*",
+
+  callback = function()
+    if vim.bo.ft ~= "fugitive" then
+      return
+    end
+
+    local bufnr = vim.api.nvim_get_current_buf()
+    local opts = { buffer = bufnr, remap = false }
+
+    vim.keymap.set("n", "<leader>p", function()
+      vim.cmd.Git('push')
+    end, opts)
+
+    vim.keymap.set("n", "<leader>P", function()
+      vim.cmd.Git({'pull',  '--rebase'})
+    end, opts)
+  end,
+})