feat(debug): graduate proc debug to Snacks.debug.cmd

This commit is contained in:
Folke Lemaitre 2025-02-16 22:56:28 +01:00
parent 95878ad32a
commit eced3033ea
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040
3 changed files with 38 additions and 2 deletions

View file

@ -345,4 +345,40 @@ function M.metrics()
Snacks.notify.warn(lines, { title = "Metrics" })
end
---@param opts {cmd: string|string[], args?: string[], cwd?: string}
function M.cmd(opts)
local cmd = opts.cmd
local args = opts.args or {}
if type(cmd) == "table" then
vim.list_extend(args, cmd, 2)
cmd = cmd[1]
end
---@cast cmd string
vim.schedule(function()
local lines = { cmd } ---@type string[]
for _, arg in ipairs(args or {}) do
arg = arg:find("[$%s]") and vim.fn.shellescape(arg) or arg
if #arg + #lines[#lines] > 40 then
lines[#lines] = lines[#lines] .. " \\"
table.insert(lines, " " .. arg)
else
lines[#lines] = lines[#lines] .. " " .. arg
end
end
local id = cmd
for _, a in ipairs(args or {}) do
if a:find("^-") then
id = id .. " " .. a
end
end
Snacks.notify.info(
("- **cwd**: `%s`\n```sh\n%s\n```"):format(
vim.fn.fnamemodify(vim.fs.normalize(opts.cwd or uv.cwd() or "."), ":~"),
table.concat(lines, "\n")
),
{ id = "snacks.debug.cmd." .. id, title = "Cmd Debug" }
)
end)
end
return M

View file

@ -182,7 +182,7 @@ function M.cmd(cmd, ctx, opts)
if ctx.picker.opts.debug.proc then
local args = vim.deepcopy(cmd)
table.remove(args, 1)
require("snacks.picker.source.proc").debug({ cmd = cmd[1], args = args, cwd = ctx.item.cwd })
Snacks.debug.cmd({ cmd = cmd[1], args = args, cwd = ctx.item.cwd })
end
---@param text string

View file

@ -40,7 +40,7 @@ function M.proc(opts, ctx)
end
if ctx.picker.opts.debug.proc then
M.debug(opts)
Snacks.debug.cmd(opts)
end
local sep = opts.sep or "\n"