Add keymap for Git files to quickfix list
Introduced a new keymap `<leader>gf` to send modified, deleted, and untracked Git files to the quickfix list with their status indicators. This enhances the Git workflow by complementing existing mappings.
This commit is contained in:
parent
82fc5b1953
commit
1e91693cf5
4 changed files with 53 additions and 1 deletions
|
|
@ -50,6 +50,57 @@ map('n', '<leader>xt', function()
|
|||
vim.diagnostic.enable(not vim.diagnostic.is_enabled())
|
||||
end, { desc = 'Diagnostics: Toggle display', silent = true })
|
||||
|
||||
-- Git: Modified, deleted, and untracked files to quickfix
|
||||
map('n', '<leader>gf', function()
|
||||
-- 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
|
||||
end
|
||||
|
||||
local result = handle:read('*a')
|
||||
handle:close()
|
||||
|
||||
if result == '' then
|
||||
vim.notify('No git changes found', vim.log.levels.INFO)
|
||||
return
|
||||
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
|
||||
|
||||
vim.fn.setqflist(qf_list, 'r')
|
||||
vim.cmd('copen')
|
||||
end, { desc = 'Git: Changed files to quickfix (with status)', silent = true })
|
||||
|
||||
-- Debug: Show highlight group and color under cursor
|
||||
map('n', '<leader>hi', function()
|
||||
local cursor_pos = vim.api.nvim_win_get_cursor(0)
|
||||
|
|
|
|||
|
|
@ -52,7 +52,6 @@ return {
|
|||
|
||||
-- Quickfix/Location list
|
||||
map('n', '<leader>hq', function() gs.setqflist('all') end, { desc = 'Gitsigns: All hunks to quickfix' })
|
||||
map('n', '<leader>hl', function() gs.setloclist(0) end, { desc = 'Gitsigns: Buffer hunks to loclist' })
|
||||
|
||||
-- Text object
|
||||
map({ 'o', 'x' }, 'ih', ':<C-U>Gitsigns select_hunk<CR>', { desc = 'Gitsigns: Select hunk' })
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue