Files
2026-09-11 21:32:43 +02:00

49 lines
1.6 KiB
Lua

local ns = vim.api.nvim_create_namespace('git_status')
local hls = { M = 'DiagnosticWarn', ['?'] = 'DiagnosticInfo', A = 'DiagnosticOk', D = 'DiagnosticError', R = 'DiagnosticWarn' }
local function show(buf_id, items, query)
MiniPick.default_show(buf_id, items, query)
vim.api.nvim_buf_clear_namespace(buf_id, ns, 0, -1)
for i, item in ipairs(items) do
if item.hl then
vim.api.nvim_buf_set_extmark(buf_id, ns, i - 1, 1, { end_col = 3, hl_group = item.hl, priority = 202, hl_mode = 'combine' })
end
end
end
return {
status = function()
local lines = vim.fn.systemlist('git status -s -u')
if vim.v.shell_error ~= 0 then
return vim.notify('Not a git repository', vim.log.levels.WARN)
end
local items = {}
for _, l in ipairs(lines) do
local s = l:sub(1, 2):match('%S+')
local p = l:sub(4):gsub('.* %-> ', ''):gsub('^"(.*)"$', '%1')
local hl = l:sub(1, 1) ~= ' ' and l:sub(1, 1) ~= '?' and 'DiagnosticOk' or hls[s:sub(1, 1)]
items[#items + 1] = {
text = string.format(' %-2s %s', s == '??' and '?' or s, p),
path = p,
hl = hl,
}
end
if #items == 0 then return vim.notify('No changes', vim.log.levels.INFO) end
MiniPick.start({
source = { items = items, name = 'Git Status', show = show },
mappings = {
quickfix = {
char = '<C-q>',
func = function()
local m = MiniPick.get_picker_matches()
MiniPick.default_choose_marked(#m.marked > 0 and m.marked or m.all)
return true
end,
},
},
})
end,
}