| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- return {
- {
- "lewis6991/gitsigns.nvim",
- enabled = true,
- lazy = false,
- dependencies = { "nvim-telescope/telescope.nvim", { "command-palette" } },
- config = function(_, opts)
- local gitsigns = require("gitsigns")
- gitsigns.setup {
- diff_opts = {
- internal = true,
- linematch = 1,
- algorithm = "minimal"
- },
- signcolumn = true,
- numhl = false,
- linehl = false,
- max_file_length = 50000,
- word_diff = false,
- auto_attach = true,
- attach_to_untracked = true
- }
- local pickers = require("telescope.pickers")
- local actions = require("telescope.actions")
- local action_state = require("telescope.actions.state")
- local finders = require("telescope.finders")
- local conf = require("telescope.config").values
- local entry_display = require("telescope.pickers.entry_display")
- local palette = require("command-palette")
- local open_picker = function(title, command)
- local displayer = entry_display.create({
- separator = " ▏",
- items = {
- { width = 16 }, { width = 64 }, { width = 24 },
- { remaining = true }
- }
- })
- local branches = vim.split(vim.fn.system(
- "git branch --list --sort committerdate --format '%(refname) ||!|| %(committerdate:relative) ||!|| branch: %(refname:short) ||!|| %(authorname) ||!|| %(subject)' | tac"),
- "\n")
- local commits = vim.split(vim.fn.system(
- "git log --branches=\\* --pretty='format:%H ||!|| %cr ||!|| %(decorate:prefix=,suffix=,separator= ) ||!|| %an ||!|| %s'"),
- "\n")
- local results = {}
- for _, v in pairs(branches) do
- if string.len(v) > 10 then
- table.insert(results, v)
- end
- end
- for _, v in pairs(commits) do
- if string.len(v) > 10 then
- table.insert(results, v)
- end
- end
- pickers.new(opts, {
- prompt_title = title,
- finder = finders.new_table({
- results = results,
- entry_maker = function(entry)
- local s = vim.split(entry, "||!||")
- return {
- value = s[1],
- display = function()
- return displayer({
- { s[2] }, { s[3] }, { s[4] }, { s[5] }
- })
- end,
- ordinal = string.format("%s %s", s[3], s[5])
- }
- end
- }),
- sorter = conf.generic_sorter(),
- attach_mappings = function(prompt_bufnr, _)
- actions.select_default:replace(function()
- actions.close(prompt_bufnr)
- local hash = action_state.get_selected_entry().value
- if command == "base" then
- vim.api.nvim_exec(
- ":Gitsigns change_base " .. hash .. " true",
- true)
- elseif command == "diff" then
- vim.api.nvim_exec(":Gitsigns diffthis " .. hash,
- true)
- end
- end)
- return true
- end
- }):find()
- end
- local open_diff_picker =
- function()
- open_picker("Gitsigns Diff", "diff")
- end
- local open_base_picker = function()
- open_picker("Gitsigns Change Base", "base")
- end
- vim.keymap.set("n", "Sgd", open_diff_picker)
- vim.keymap.set("n", "Sgb", open_base_picker)
- palette.add({
- {
- "Gitsigns", "", {
- {
- "Diff file",
- "Open the Gitsigns differ for this file",
- open_diff_picker
- },
- {
- "Change diff base",
- "Change base branch for Gitsigns to diff again",
- open_base_picker
- }
- }
- }
- })
- end
- }
- }
|