fix(debug): better args handling for debugging cmds

This commit is contained in:
Folke Lemaitre 2025-02-17 12:44:05 +01:00
parent a33f65d936
commit 48a3fed3c5
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040

View file

@ -348,16 +348,17 @@ end
---@param opts {cmd: string|string[], args?: string[], cwd?: string}
function M.cmd(opts)
local cmd = opts.cmd
local args = opts.args or {}
local args = vim.deepcopy(opts.args or {})
if type(cmd) == "table" then
vim.list_extend(args, cmd, 2)
cmd = cmd[1]
end
args = vim.tbl_map(tostring, args)
---@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
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)