feat: cmdline tab improvements

This commit is contained in:
Barrett Ruth 2026-03-28 12:18:33 -04:00
parent c677feee2f
commit 597788b447
No known key found for this signature in database
GPG key ID: A6C96C9349D2FC81
2 changed files with 14 additions and 52 deletions

View file

@ -28,17 +28,6 @@ local function to_fzf_key(key)
end) end)
end end
local function make_header(bindings)
local utils = require('fzf-lua.utils')
local parts = {}
for _, b in ipairs(bindings) do
local key = utils.ansi_from_hl('FzfLuaHeaderBind', b[1])
local desc = utils.ansi_from_hl('FzfLuaHeaderText', b[2])
table.insert(parts, key .. ' to ' .. desc)
end
return ':: ' .. table.concat(parts, '|')
end
local function build_actions(picker_name, action_defs) local function build_actions(picker_name, action_defs)
local cfg = require('forge').config() local cfg = require('forge').config()
local keys = cfg.keys local keys = cfg.keys
@ -47,18 +36,13 @@ local function build_actions(picker_name, action_defs)
end end
local bindings = keys[picker_name] or {} local bindings = keys[picker_name] or {}
local actions = {} local actions = {}
local header_entries = {}
for _, def in ipairs(action_defs) do for _, def in ipairs(action_defs) do
local key = bindings[def.name] local key = bindings[def.name]
if key then if key then
local fzf_key = to_fzf_key(key) actions[to_fzf_key(key)] = def.fn
actions[fzf_key] = def.fn
if def.label then
table.insert(header_entries, { key, def.label })
end
end end
end end
return actions, make_header(header_entries) return actions
end end
---@param kind string ---@param kind string
@ -319,10 +303,9 @@ function M.checks(f, num, filter, cached_checks)
pending = 'running', pending = 'running',
} }
local check_actions, check_header = build_actions('ci', { local check_actions = build_actions('ci', {
{ {
name = 'log', name = 'log',
label = 'log',
fn = function(selected) fn = function(selected)
local c = get_check(selected) local c = get_check(selected)
if not c then if not c then
@ -354,7 +337,6 @@ function M.checks(f, num, filter, cached_checks)
}, },
{ {
name = 'browse', name = 'browse',
label = 'browse',
fn = function(selected) fn = function(selected)
local c = get_check(selected) local c = get_check(selected)
if c and c.link then if c and c.link then
@ -364,28 +346,24 @@ function M.checks(f, num, filter, cached_checks)
}, },
{ {
name = 'failed', name = 'failed',
label = 'failed',
fn = function() fn = function()
M.checks(f, num, 'fail', checks) M.checks(f, num, 'fail', checks)
end, end,
}, },
{ {
name = 'passed', name = 'passed',
label = 'passed',
fn = function() fn = function()
M.checks(f, num, 'pass', checks) M.checks(f, num, 'pass', checks)
end, end,
}, },
{ {
name = 'running', name = 'running',
label = 'running',
fn = function() fn = function()
M.checks(f, num, 'pending', checks) M.checks(f, num, 'pending', checks)
end, end,
}, },
{ {
name = 'all', name = 'all',
label = 'all',
fn = function() fn = function()
M.checks(f, num, 'all', checks) M.checks(f, num, 'all', checks)
end, end,
@ -400,7 +378,6 @@ function M.checks(f, num, filter, cached_checks)
['--no-multi'] = '', ['--no-multi'] = '',
['--with-nth'] = '2..', ['--with-nth'] = '2..',
['--delimiter'] = '\t', ['--delimiter'] = '\t',
['--header'] = check_header,
}, },
actions = check_actions, actions = check_actions,
}) })
@ -463,10 +440,9 @@ function M.ci(f, branch)
return idx and normalized[idx] or nil return idx and normalized[idx] or nil
end end
local ci_actions, ci_header = build_actions('ci', { local ci_actions = build_actions('ci', {
{ {
name = 'log', name = 'log',
label = 'log',
fn = function(selected) fn = function(selected)
local run = get_run(selected) local run = get_run(selected)
if not run then if not run then
@ -496,7 +472,6 @@ function M.ci(f, branch)
}, },
{ {
name = 'browse', name = 'browse',
label = 'browse',
fn = function(selected) fn = function(selected)
local run = get_run(selected) local run = get_run(selected)
if run and run.url ~= '' then if run and run.url ~= '' then
@ -506,7 +481,6 @@ function M.ci(f, branch)
}, },
{ {
name = 'refresh', name = 'refresh',
label = 'refresh',
fn = function() fn = function()
M.ci(f, branch) M.ci(f, branch)
end, end,
@ -521,7 +495,6 @@ function M.ci(f, branch)
['--no-multi'] = '', ['--no-multi'] = '',
['--with-nth'] = '2..', ['--with-nth'] = '2..',
['--delimiter'] = '\t', ['--delimiter'] = '\t',
['--header'] = ci_header,
}, },
actions = ci_actions, actions = ci_actions,
}) })
@ -566,7 +539,6 @@ function M.commits(f)
local defs = { local defs = {
{ {
name = 'checkout', name = 'checkout',
label = 'checkout',
fn = function(selected) fn = function(selected)
with_sha(selected, function(sha) with_sha(selected, function(sha)
forge_mod.log_now('checking out ' .. sha .. '...') forge_mod.log_now('checking out ' .. sha .. '...')
@ -588,7 +560,6 @@ function M.commits(f)
}, },
{ {
name = 'diff', name = 'diff',
label = 'diff',
fn = function(selected) fn = function(selected)
with_sha(selected, function(sha) with_sha(selected, function(sha)
local range = sha .. '^..' .. sha local range = sha .. '^..' .. sha
@ -603,7 +574,6 @@ function M.commits(f)
}, },
{ {
name = 'browse', name = 'browse',
label = 'browse',
fn = function(selected) fn = function(selected)
with_sha(selected, function(sha) with_sha(selected, function(sha)
if f then if f then
@ -614,7 +584,6 @@ function M.commits(f)
}, },
{ {
name = 'yank', name = 'yank',
label = 'yank hash',
fn = function(selected) fn = function(selected)
with_sha(selected, function(sha) with_sha(selected, function(sha)
vim.fn.setreg('+', sha) vim.fn.setreg('+', sha)
@ -624,7 +593,7 @@ function M.commits(f)
}, },
} }
local commit_actions, commit_header = build_actions('commits', defs) local commit_actions = build_actions('commits', defs)
require('fzf-lua').fzf_exec(log_cmd, { require('fzf-lua').fzf_exec(log_cmd, {
fzf_args = fzf_args, fzf_args = fzf_args,
@ -633,7 +602,6 @@ function M.commits(f)
['--ansi'] = '', ['--ansi'] = '',
['--no-multi'] = '', ['--no-multi'] = '',
['--preview'] = 'git show --color {1}', ['--preview'] = 'git show --color {1}',
['--header'] = commit_header,
}, },
actions = commit_actions, actions = commit_actions,
}) })
@ -703,10 +671,9 @@ function M.pr(state, f)
end end
end end
local list_actions, list_header = build_actions('pr', { local list_actions = build_actions('pr', {
{ {
name = 'checkout', name = 'checkout',
label = 'checkout',
fn = function(selected) fn = function(selected)
with_pr_num(selected, function(num) with_pr_num(selected, function(num)
pr_actions(f, num)._by_name.checkout() pr_actions(f, num)._by_name.checkout()
@ -715,7 +682,6 @@ function M.pr(state, f)
}, },
{ {
name = 'diff', name = 'diff',
label = 'diff',
fn = function(selected) fn = function(selected)
with_pr_num(selected, function(num) with_pr_num(selected, function(num)
pr_actions(f, num)._by_name.diff() pr_actions(f, num)._by_name.diff()
@ -724,7 +690,6 @@ function M.pr(state, f)
}, },
{ {
name = 'worktree', name = 'worktree',
label = 'worktree',
fn = function(selected) fn = function(selected)
with_pr_num(selected, function(num) with_pr_num(selected, function(num)
pr_actions(f, num)._by_name.worktree() pr_actions(f, num)._by_name.worktree()
@ -733,7 +698,6 @@ function M.pr(state, f)
}, },
{ {
name = 'ci', name = 'ci',
label = 'ci',
fn = function(selected) fn = function(selected)
with_pr_num(selected, function(num) with_pr_num(selected, function(num)
pr_actions(f, num)._by_name.ci() pr_actions(f, num)._by_name.ci()
@ -742,7 +706,6 @@ function M.pr(state, f)
}, },
{ {
name = 'browse', name = 'browse',
label = 'browse',
fn = function(selected) fn = function(selected)
with_pr_num(selected, function(num) with_pr_num(selected, function(num)
f:view_web(cli_kind, num) f:view_web(cli_kind, num)
@ -751,7 +714,6 @@ function M.pr(state, f)
}, },
{ {
name = 'manage', name = 'manage',
label = 'manage',
fn = function(selected) fn = function(selected)
with_pr_num(selected, function(num) with_pr_num(selected, function(num)
pr_actions(f, num)._by_name.manage() pr_actions(f, num)._by_name.manage()
@ -760,14 +722,12 @@ function M.pr(state, f)
}, },
{ {
name = 'create', name = 'create',
label = 'new',
fn = function() fn = function()
forge_mod.create_pr() forge_mod.create_pr()
end, end,
}, },
{ {
name = 'filter', name = 'filter',
label = 'filter',
fn = function() fn = function()
M.pr(next_state, f) M.pr(next_state, f)
end, end,
@ -787,7 +747,6 @@ function M.pr(state, f)
fzf_opts = { fzf_opts = {
['--ansi'] = '', ['--ansi'] = '',
['--no-multi'] = '', ['--no-multi'] = '',
['--header'] = list_header,
}, },
actions = list_actions, actions = list_actions,
}) })

View file

@ -382,11 +382,14 @@ local function complete(arglead, cmdline, _)
local flag, value_prefix = arglead:match('^(%-%-[^=]+)=(.*)$') local flag, value_prefix = arglead:match('^(%-%-[^=]+)=(.*)$')
if flag and flag_values[flag] then if flag and flag_values[flag] then
return vim.tbl_map(function(v) return vim.tbl_map(
return flag .. '=' .. v function(v)
end, vim.tbl_filter(function(v) return flag .. '=' .. v
return v:find(value_prefix, 1, true) == 1 end,
end, flag_values[flag])) vim.tbl_filter(function(v)
return v:find(value_prefix, 1, true) == 1
end, flag_values[flag])
)
end end
if arg_idx == 1 then if arg_idx == 1 then