fix: improve git workflow
This commit is contained in:
+38
@@ -0,0 +1,38 @@
|
||||
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
|
||||
local hl = hls[item.text:match('%S')]
|
||||
if hl then
|
||||
vim.api.nvim_buf_set_extmark(buf_id, ns, i - 1, 0, { end_col = 2, hl_group = hl, priority = 202, hl_mode = 'combine' })
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return {
|
||||
status = function()
|
||||
local items = {}
|
||||
for _, l in ipairs(vim.fn.systemlist('git status -s -u')) do
|
||||
local p = l:sub(4):gsub('.* %-> ', '')
|
||||
if vim.uv.fs_stat(p) then items[#items + 1] = { text = l, path = p } end
|
||||
end
|
||||
if #items == 0 then return vim.notify('No changes') 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,
|
||||
}
|
||||
+8
-15
@@ -1,26 +1,19 @@
|
||||
local M = {}
|
||||
|
||||
-- Open a command in a simple centered floating window
|
||||
function M.open_terminal_app(cmd)
|
||||
local buf = vim.api.nvim_create_buf(false, true)
|
||||
vim.bo[buf].bufhidden = "wipe"
|
||||
|
||||
local function open(cmd)
|
||||
local lines = vim.o.lines - vim.o.cmdheight - (vim.o.laststatus > 0 and 1 or 0)
|
||||
local w = math.floor(vim.o.columns * 0.95)
|
||||
local h = math.floor(lines * 0.95)
|
||||
local w, h = math.floor(vim.o.columns * 0.95), math.floor(lines * 0.95)
|
||||
local buf = vim.api.nvim_create_buf(false, true)
|
||||
vim.bo[buf].bufhidden = 'wipe'
|
||||
|
||||
local win = vim.api.nvim_open_win(buf, true, {
|
||||
relative = "editor",
|
||||
relative = 'editor',
|
||||
width = w,
|
||||
height = h,
|
||||
row = math.floor((lines - h) / 2),
|
||||
col = math.floor((vim.o.columns - w) / 2),
|
||||
border = "rounded",
|
||||
border = 'rounded',
|
||||
})
|
||||
|
||||
vim.fn.termopen(cmd, {
|
||||
on_exit = function() pcall(vim.api.nvim_win_close, win, true) end,
|
||||
})
|
||||
vim.fn.termopen(cmd, { on_exit = function() pcall(vim.api.nvim_win_close, win, true) end })
|
||||
end
|
||||
|
||||
return M
|
||||
return { open = open }
|
||||
|
||||
Reference in New Issue
Block a user