mirror of
https://github.com/folke/snacks.nvim
synced 2025-08-04 18:58:12 +00:00
feat(debug): graduate proc debug to Snacks.debug.cmd
This commit is contained in:
parent
95878ad32a
commit
eced3033ea
3 changed files with 38 additions and 2 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue