0
0

git.lua 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. return {
  2. {
  3. "lewis6991/gitsigns.nvim",
  4. enabled = true,
  5. lazy = false,
  6. dependencies = { "nvim-telescope/telescope.nvim", { "command-palette" } },
  7. config = function(_, opts)
  8. local gitsigns = require("gitsigns")
  9. gitsigns.setup {
  10. diff_opts = {
  11. internal = true,
  12. linematch = 1,
  13. algorithm = "minimal"
  14. },
  15. signcolumn = true,
  16. numhl = false,
  17. linehl = false,
  18. max_file_length = 50000,
  19. word_diff = false,
  20. auto_attach = true,
  21. attach_to_untracked = true
  22. }
  23. local pickers = require("telescope.pickers")
  24. local actions = require("telescope.actions")
  25. local action_state = require("telescope.actions.state")
  26. local finders = require("telescope.finders")
  27. local conf = require("telescope.config").values
  28. local entry_display = require("telescope.pickers.entry_display")
  29. local palette = require("command-palette")
  30. local open_picker = function(title, command)
  31. local displayer = entry_display.create({
  32. separator = " ▏",
  33. items = {
  34. { width = 16 }, { width = 64 }, { width = 24 },
  35. { remaining = true }
  36. }
  37. })
  38. local results = vim.split(vim.fn.system(
  39. "git log --branches=\\* --pretty='format:%H ||!|| %cr ||!|| %(decorate:prefix=,suffix=,separator= ) ||!|| %an ||!|| %s' --since='last month'"),
  40. "\n")
  41. pickers.new(opts, {
  42. prompt_title = title,
  43. finder = finders.new_table({
  44. results = results,
  45. entry_maker = function(entry)
  46. local s = vim.split(entry, "||!||")
  47. return {
  48. value = s[1],
  49. display = function()
  50. return displayer({
  51. { s[2] }, { s[3] }, { s[4] }, { s[5] }
  52. })
  53. end,
  54. ordinal = string.format("%s %s", s[3], s[5])
  55. }
  56. end
  57. }),
  58. sorter = conf.generic_sorter(),
  59. attach_mappings = function(prompt_bufnr, _)
  60. actions.select_default:replace(function()
  61. actions.close(prompt_bufnr)
  62. local hash = action_state.get_selected_entry().value
  63. if command == "base" then
  64. vim.api.nvim_exec(
  65. ":Gitsigns change_base " .. hash .. " true",
  66. true)
  67. elseif command == "diff" then
  68. vim.api.nvim_exec(":Gitsigns diffthis " .. hash,
  69. true)
  70. end
  71. end)
  72. return true
  73. end
  74. }):find()
  75. end
  76. local open_diff_picker =
  77. function()
  78. open_picker("Gitsigns Diff", "diff")
  79. end
  80. local open_base_picker = function()
  81. open_picker("Gitsigns Change Base", "base")
  82. end
  83. vim.keymap.set("n", "Sgd", open_diff_picker)
  84. vim.keymap.set("n", "Sgb", open_base_picker)
  85. palette.add({
  86. {
  87. "Gitsigns", "", {
  88. {
  89. "Diff file",
  90. "Open the Gitsigns differ for this file",
  91. open_diff_picker
  92. },
  93. {
  94. "Change diff base",
  95. "Change base branch for Gitsigns to diff again",
  96. open_base_picker
  97. }
  98. }
  99. }
  100. })
  101. end
  102. }
  103. }