feat(util): utility method to get sync process output

This commit is contained in:
Folke Lemaitre 2022-12-21 10:12:39 +01:00
parent 3c3a711dda
commit e95da35d09
No known key found for this signature in database
GPG Key ID: 41F8B1FBACAE2040
1 changed files with 18 additions and 0 deletions

View File

@ -108,4 +108,22 @@ function M.spawn(cmd, opts)
return handle
end
---@param cmd string[]
---@param opts? {cwd:string}
function M.exec(cmd, opts)
opts = opts or {}
---@type string[]
local lines
local job = vim.fn.jobstart(cmd, {
cwd = opts.cwd,
pty = false,
stdout_buffered = true,
on_stdout = function(_, _lines)
lines = _lines
end,
})
vim.fn.jobwait({ job })
return lines
end
return M