Update keymap for Git files in quickfix list

Changed keymap from `<leader>gf` to `<leader>gg` for sending modified,
deleted, and untracked Git files to the quickfix list. Added utility
function to handle Git status parsing.
This commit is contained in:
Ray Elliott 2026-01-13 15:34:28 +00:00
commit 1b71a30520
4 changed files with 59 additions and 49 deletions

View file

@ -17,6 +17,57 @@ M.tabline_full_parents = 1
-- Example: with shorten_length = 1, /path/to/my becomes p/t/m
M.tabline_shorten_length = 3
-- Get all modified, deleted, and untracked Git files with status
-- Returns a list suitable for setqflist() or nil on error
function M.git_changed_files()
-- Use git status --porcelain to get all changes with status indicators
-- Format: "XY filename" where X=index status, Y=worktree status
-- Status codes: M=modified, D=deleted, A=added, ??=untracked, etc.
local handle = io.popen('git status --porcelain 2>/dev/null')
if not handle then
vim.notify('Failed to run git status', vim.log.levels.ERROR)
return nil
end
local result = handle:read('*a')
handle:close()
if result == '' then
vim.notify('No git changes found', vim.log.levels.INFO)
return nil
end
local qf_list = {}
local status_map = {
['M'] = 'Modified',
['A'] = 'Added',
['D'] = 'Deleted',
['R'] = 'Renamed',
['C'] = 'Copied',
['U'] = 'Unmerged',
['?'] = 'Untracked',
}
for line in result:gmatch('[^\n]+') do
-- Parse porcelain format: "XY filename" or "XY original -> renamed"
local index_status = line:sub(1, 1)
local work_status = line:sub(2, 2)
local filename = line:sub(4) -- Skip "XY " prefix
-- Determine status text (worktree takes precedence over index)
local status_code = work_status ~= ' ' and work_status or index_status
local status_text = status_map[status_code] or 'Changed'
table.insert(qf_list, {
filename = filename,
lnum = 1,
text = status_text,
})
end
return qf_list
end
-- Custom tabline function
-- Shows configurable number of full parent directories, shortens the rest
function M.custom_tabline()