From 6dadd015bf78b4ae7e8f3eebb0046ed4f1b08550 Mon Sep 17 00:00:00 2001 From: Job79 Date: Fri, 11 Sep 2026 20:41:09 +0200 Subject: [PATCH] fix: improve git workflow --- lua/git.lua | 38 ++++++++++++++++++++++++++++++++++++++ lua/terminal.lua | 23 ++++++++--------------- plugin/10_options.lua | 3 ++- plugin/20_keymaps.lua | 17 +++++------------ 4 files changed, 53 insertions(+), 28 deletions(-) create mode 100644 lua/git.lua diff --git a/lua/git.lua b/lua/git.lua new file mode 100644 index 0000000..8dca257 --- /dev/null +++ b/lua/git.lua @@ -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 = '', + 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, +} diff --git a/lua/terminal.lua b/lua/terminal.lua index e00ee4c..7f6e902 100644 --- a/lua/terminal.lua +++ b/lua/terminal.lua @@ -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 } diff --git a/plugin/10_options.lua b/plugin/10_options.lua index 8b3750a..8d91467 100644 --- a/plugin/10_options.lua +++ b/plugin/10_options.lua @@ -51,10 +51,11 @@ Config.later(function() jump = { on_jump = vim.diagnostic.open_float }, signs = { priority = 9999, - severity = { min = vim.diagnostic.severity.WARN }, + severity = { min = vim.diagnostic.severity.INFO }, text = { [vim.diagnostic.severity.ERROR] = '', [vim.diagnostic.severity.WARN] = '', + [vim.diagnostic.severity.INFO] = '', }, }, virtual_text = false, diff --git a/plugin/20_keymaps.lua b/plugin/20_keymaps.lua index 8f60378..68c4631 100644 --- a/plugin/20_keymaps.lua +++ b/plugin/20_keymaps.lua @@ -73,21 +73,14 @@ nmap_leader('fG', 'lua MiniPick.builtin.grep({ pattern = vim.fn.expand("lua MiniPick.builtin.help()', 'Help tags') nmap_leader('fl', 'lua MiniPick.builtin.buf_lines({ scope = "all" })', 'Lines (all)') nmap_leader('fL', 'lua MiniPick.builtin.buf_lines({ scope = "current" })', 'Lines (buf)') +nmap_leader('fm', 'lua require("git").status()', 'Modified / changed files') nmap_leader('fr', 'lua MiniPick.builtin.resume()', 'Resume') nmap_leader('fs', 'lua MiniExtra.pickers.lsp({ scope = "workspace_symbol_live" })', 'Symbols workspace') nmap_leader('fS', 'lua MiniExtra.pickers.lsp({ scope = "document_symbol" })', 'Symbols document') nmap_leader('f:', 'lua MiniExtra.pickers.history({ scope = ":" })', 'Command history') -- Git -local git_log_cmd = [[Git log --pretty=format:\%h\ \%as\ │\ \%s --topo-order]] -local git_log_buf_cmd = git_log_cmd .. ' --follow -- %' - -nmap_leader('ga', 'Git diff --cached', 'Added diff') -nmap_leader('gA', 'Git diff --cached -- %', 'Added diff buffer') -nmap_leader('gd', 'Git diff', 'Diff') -nmap_leader('gD', 'Git diff -- %', 'Diff buffer') -nmap_leader('gl', '' .. git_log_cmd .. '', 'Log') -nmap_leader('gL', '' .. git_log_buf_cmd .. '', 'Log buffer') +nmap_leader('ga', 'Git add %', 'Add current file') nmap_leader('go', 'lua MiniDiff.toggle_overlay()', 'Toggle overlay') nmap_leader('gs', 'lua MiniGit.show_at_cursor()', 'Show at cursor') xmap_leader('gs', 'lua MiniGit.show_at_cursor()', 'Show at selection') @@ -112,9 +105,9 @@ nmap_leader('rs', 'lua require("kulala").run()', 'Send HTTP request') nmap_leader('tT', 'horizontal term', 'Terminal (horizontal)') nmap_leader('tt', 'vertical term', 'Terminal (vertical)') nmap_leader('tc', 'vertical term claude', 'Claude') -nmap_leader('tf', 'lua require("terminal").open_terminal_app(vim.o.shell)', 'Terminal (popup)') -nmap_leader('tg', 'lua require("terminal").open_terminal_app("lazygit")', 'LazyGit') -nmap_leader('ts', 'lua require("terminal").open_terminal_app("lazysql")', 'LazySQL') +nmap_leader('tf', 'lua require("terminal").open(vim.o.shell)', 'Terminal (popup)') +nmap_leader('tg', 'lua require("terminal").open("lazygit")', 'LazyGit') +nmap_leader('ts', 'lua require("terminal").open("lazysql")', 'LazySQL') -- Tabs nmap_leader('', 'tabnew', 'New tab')