From e95da35d09989d15122ec4bb1364d9c36e36317d Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Wed, 21 Dec 2022 10:12:39 +0100 Subject: [PATCH] feat(util): utility method to get sync process output --- lua/lazy/manage/process.lua | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/lua/lazy/manage/process.lua b/lua/lazy/manage/process.lua index 633d12d..8b11674 100644 --- a/lua/lazy/manage/process.lua +++ b/lua/lazy/manage/process.lua @@ -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