feat: expand cli

This commit is contained in:
Barrett Ruth 2026-03-28 12:12:04 -04:00
parent b4db29e77a
commit c677feee2f
No known key found for this signature in database
GPG key ID: A6C96C9349D2FC81
5 changed files with 142 additions and 387 deletions

View file

@ -36,13 +36,6 @@ function M.check()
vim.health.info('diffs.nvim not found (review mode disabled)')
end
local has_fugitive = vim.fn.exists(':Git') == 2
if has_fugitive then
vim.health.ok('vim-fugitive found (fugitive keymaps available)')
else
vim.health.info('vim-fugitive not found (fugitive keymaps disabled)')
end
local forge_mod = require('forge')
for name, source in pairs(forge_mod.registered_sources()) do
if name ~= 'github' and name ~= 'gitlab' and name ~= 'codeberg' then

View file

@ -4,7 +4,6 @@ local M = {}
---@field ci forge.CIConfig
---@field sources table<string, forge.SourceConfig>
---@field keys forge.KeysConfig|false
---@field picker_keys forge.PickerKeysConfig|false
---@field display forge.DisplayConfig
---@class forge.CIConfig
@ -14,25 +13,8 @@ local M = {}
---@field hosts string[]
---@class forge.KeysConfig
---@field picker string|false
---@field next_qf string|false
---@field prev_qf string|false
---@field next_loc string|false
---@field prev_loc string|false
---@field review_toggle string|false
---@field terminal_open string|false
---@field fugitive forge.FugitiveKeysConfig|false
---@class forge.FugitiveKeysConfig
---@field create string|false
---@field create_draft string|false
---@field create_fill string|false
---@field create_web string|false
---@class forge.PickerKeysConfig
---@field pr forge.PRPickerKeys
---@field issue forge.IssuePickerKeys
---@field checks forge.ChecksPickerKeys
---@field ci forge.CIPickerKeys
---@field commits forge.CommitsPickerKeys
---@field branches forge.BranchesPickerKeys
@ -41,30 +23,26 @@ local M = {}
---@field checkout string|false
---@field diff string|false
---@field worktree string|false
---@field checks string|false
---@field ci string|false
---@field browse string|false
---@field manage string|false
---@field create string|false
---@field toggle string|false
---@field filter string|false
---@field refresh string|false
---@class forge.IssuePickerKeys
---@field browse string|false
---@field close_reopen string|false
---@field toggle string|false
---@field close string|false
---@field filter string|false
---@field refresh string|false
---@class forge.ChecksPickerKeys
---@class forge.CIPickerKeys
---@field log string|false
---@field browse string|false
---@field failed string|false
---@field passed string|false
---@field running string|false
---@field all string|false
---@class forge.CIPickerKeys
---@field log string|false
---@field browse string|false
---@field refresh string|false
---@class forge.CommitsPickerKeys
@ -108,44 +86,29 @@ local DEFAULTS = {
ci = { lines = 10000 },
sources = {},
keys = {
picker = '<c-g>',
next_qf = ']q',
prev_qf = '[q',
next_loc = ']l',
prev_loc = '[l',
review_toggle = 's',
terminal_open = 'gx',
fugitive = {
create = 'cpr',
create_draft = 'cpd',
create_fill = 'cpf',
create_web = 'cpw',
},
},
picker_keys = {
pr = {
checkout = 'default',
diff = 'ctrl-d',
worktree = 'ctrl-w',
checks = 'ctrl-t',
browse = 'ctrl-x',
manage = 'ctrl-e',
create = 'ctrl-a',
toggle = 'ctrl-o',
refresh = 'ctrl-r',
checkout = '<cr>',
diff = '<c-d>',
worktree = '<c-w>',
ci = '<c-t>',
browse = '<c-x>',
manage = '<c-e>',
create = '<c-a>',
filter = '<c-o>',
refresh = '<c-r>',
},
issue = { browse = 'default', close_reopen = 'ctrl-s', toggle = 'ctrl-o', refresh = 'ctrl-r' },
checks = {
log = 'default',
browse = 'ctrl-x',
failed = 'ctrl-f',
passed = 'ctrl-p',
running = 'ctrl-n',
all = 'ctrl-a',
issue = { browse = '<cr>', close = '<c-s>', filter = '<c-o>', refresh = '<c-r>' },
ci = {
log = '<cr>',
browse = '<c-x>',
failed = '<c-f>',
passed = '<c-p>',
running = '<c-n>',
all = '<c-a>',
refresh = '<c-r>',
},
ci = { log = 'default', browse = 'ctrl-x', refresh = 'ctrl-r' },
commits = { checkout = 'default', diff = 'ctrl-d', browse = 'ctrl-x', yank = 'ctrl-y' },
branches = { diff = 'ctrl-d', browse = 'ctrl-x' },
commits = { checkout = '<cr>', diff = '<c-d>', browse = '<c-x>', yank = '<c-y>' },
branches = { diff = '<c-d>', browse = '<c-x>' },
},
display = {
icons = {
@ -749,9 +712,6 @@ function M.config()
if user.keys == false then
cfg.keys = false
end
if user.picker_keys == false then
cfg.picker_keys = false
end
return cfg
end

View file

@ -19,11 +19,20 @@ local fzf_args = (vim.env.FZF_DEFAULT_OPTS or '')
:gsub('%-%-bind=[^%s]+', '')
:gsub('%-%-color=[^%s]+', '')
local function to_fzf_key(key)
if key == '<cr>' then
return 'default'
end
return key:gsub('<c%-(%a)>', function(ch)
return 'ctrl-' .. ch:lower()
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 key = utils.ansi_from_hl('FzfLuaHeaderBind', b[1])
local desc = utils.ansi_from_hl('FzfLuaHeaderText', b[2])
table.insert(parts, key .. ' to ' .. desc)
end
@ -32,34 +41,26 @@ end
local function build_actions(picker_name, action_defs)
local cfg = require('forge').config()
local pk = cfg.picker_keys
if pk == false then
pk = {}
local keys = cfg.keys
if keys == false then
keys = {}
end
local bindings = pk[picker_name] or {}
local bindings = keys[picker_name] or {}
local actions = {}
local header_entries = {}
for _, def in ipairs(action_defs) do
local key = bindings[def.name]
if key then
actions[key] = def.fn
local fzf_key = to_fzf_key(key)
actions[fzf_key] = def.fn
if def.label then
local display_key = key == 'default' and 'enter' or key:gsub('ctrl%-', 'ctrl-')
table.insert(header_entries, { display_key, def.label })
table.insert(header_entries, { key, def.label })
end
end
end
return actions, make_header(header_entries)
end
local function terminal_open_key()
local cfg = require('forge').config()
if cfg.keys == false then
return nil
end
return cfg.keys.terminal_open
end
---@param kind string
---@param num string
---@param label string
@ -188,7 +189,7 @@ local function pr_actions(f, num)
end,
},
{
name = 'checks',
name = 'ci',
fn = function()
M.checks(f, num)
end,
@ -318,7 +319,7 @@ function M.checks(f, num, filter, cached_checks)
pending = 'running',
}
local check_actions, check_header = build_actions('checks', {
local check_actions, check_header = build_actions('ci', {
{
name = 'log',
label = 'log',
@ -346,15 +347,8 @@ function M.checks(f, num, filter, cached_checks)
'n',
false
)
local to_key = terminal_open_key()
if c.link and to_key then
if c.link then
vim.b.forge_check_url = c.link
vim.keymap.set('n', to_key, function()
vim.ui.open(vim.b.forge_check_url)
end, {
buffer = true,
desc = 'open check in browser',
})
end
end,
},
@ -495,15 +489,8 @@ function M.ci(f, branch)
'n',
false
)
local to_key = terminal_open_key()
if run.url ~= '' and to_key then
if run.url ~= '' then
vim.b.forge_run_url = run.url
vim.keymap.set('n', to_key, function()
vim.ui.open(vim.b.forge_run_url)
end, {
buffer = true,
desc = 'open run in browser',
})
end
end,
},
@ -745,11 +732,11 @@ function M.pr(state, f)
end,
},
{
name = 'checks',
label = 'checks',
name = 'ci',
label = 'ci',
fn = function(selected)
with_pr_num(selected, function(num)
pr_actions(f, num)._by_name.checks()
pr_actions(f, num)._by_name.ci()
end)
end,
},
@ -779,8 +766,8 @@ function M.pr(state, f)
end,
},
{
name = 'toggle',
label = 'toggle',
name = 'filter',
label = 'filter',
fn = function()
M.pr(next_state, f)
end,
@ -865,7 +852,7 @@ function M.issue(state, f)
end,
},
{
name = 'close_reopen',
name = 'close',
label = 'close/reopen',
fn = function(selected)
with_issue_num(selected, function(num)
@ -874,8 +861,8 @@ function M.issue(state, f)
end,
},
{
name = 'toggle',
label = 'toggle',
name = 'filter',
label = 'filter',
fn = function()
M.issue(next_state, f)
end,