git.lua 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. local M = {
  2. {
  3. "tpope/vim-fugitive",
  4. config = function()
  5. local git_status = function()
  6. local bufnr = vim.api.nvim_get_current_buf()
  7. if vim.b[bufnr].fugitive_status then
  8. local winnr = vim.fn.bufwinid(bufnr)
  9. vim.api.nvim_win_close(winnr, true)
  10. else
  11. vim.cmd("G")
  12. end
  13. end
  14. vim.g.fugitive_git_executable = "env GPG_TTY=$(tty) git"
  15. vim.env.GPG_TTY = vim.fn.system("tty"):gsub("\n", "")
  16. nmap("<leader>lg", ":G<cr>", { desc = "Git Status" })
  17. nmap("<leader>gs", git_status, { desc = "Toggle Git Status" })
  18. nmap("gs", git_status, { desc = "Toggle Git Status" })
  19. vim.api.nvim_create_autocmd("FileType", {
  20. pattern = { "fugitive", "fugitiveblame", "fugitive-status" },
  21. callback = function()
  22. nmap("P", function()
  23. local cmd = "git push --force-with-lease"
  24. Snacks.notifier.notify("Pushing...", vim.log.levels.INFO)
  25. vim.fn.jobstart(cmd, {
  26. on_exit = function(_, code)
  27. if code == 0 then
  28. Snacks.notifier.notify("Push completed successfully", vim.log.levels.INFO)
  29. else
  30. Snacks.notifier.notify("Push failed with exit code: " .. code, vim.log.levels.ERROR)
  31. end
  32. end,
  33. detach = true,
  34. })
  35. end, { buffer = true, desc = "Git Push Force With Lease (Async)" })
  36. nmap("<C-c>", function()
  37. local win_id = vim.api.nvim_get_current_win()
  38. vim.api.nvim_win_close(win_id, false)
  39. end, { buffer = true, desc = "Close window" })
  40. -- Git Pull
  41. nmap("gp", function()
  42. local cmd = "git pull"
  43. Snacks.notifier.notify("Pulling...", vim.log.levels.INFO)
  44. vim.fn.jobstart(cmd, {
  45. on_exit = function(_, code)
  46. if code == 0 then
  47. Snacks.notifier.notify("Pull completed successfully", vim.log.levels.INFO)
  48. else
  49. Snacks.notifier.notify("Pull failed with exit code: " .. code, vim.log.levels.ERROR)
  50. end
  51. end,
  52. detach = true,
  53. })
  54. end, { buffer = true, desc = "Close window" })
  55. end,
  56. })
  57. end,
  58. },
  59. {
  60. "lewis6991/gitsigns.nvim",
  61. config = function()
  62. require("gitsigns").setup({
  63. current_line_blame_formatter = "<author>, <author_time:%Y-%m-%d> - <summary>",
  64. current_line_blame = true,
  65. signs = {
  66. add = { text = icons.ui.BoldLineMiddle },
  67. change = { text = icons.ui.BoldLineDashedMiddle },
  68. delete = { text = icons.ui.TriangleShortArrowRight },
  69. topdelete = { text = icons.ui.TriangleShortArrowRight },
  70. changedelete = { text = icons.ui.BoldLineMiddle },
  71. },
  72. })
  73. end,
  74. },
  75. {
  76. "ruifm/gitlinker.nvim",
  77. config = function()
  78. require("gitlinker").setup({
  79. message = false,
  80. console_log = false,
  81. })
  82. nmap("<leader>gy", "<cmd>lua require('gitlinker').get_buf_range_url('n')<cr>")
  83. end,
  84. },
  85. }
  86. return M