diff options
Diffstat (limited to '.vim/lua/job.lua')
| -rw-r--r-- | .vim/lua/job.lua | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/.vim/lua/job.lua b/.vim/lua/job.lua new file mode 100644 index 0000000..a3591e5 --- /dev/null +++ b/.vim/lua/job.lua @@ -0,0 +1,45 @@ + +local M = {} + +function M.jobstart(cmd) + local output = {} + + local function on_event(job_id, data, event) + if event == 'stdout' or event == 'stderr' then + if data then + vim.list_extend(output, data) + end + end + if event == 'exit' then + vim.fn.setqflist({}, ' ', { + title = cmd, + lines = output, + }) + vim.api.nvim_command('doautocmd QuickFixCmdPost') + end + end + + local job_id = require('spinner.job').jobstart(cmd, { + on_stdout = on_event, + on_stderr = on_event, + on_exit = on_event, + stdout_buffered = true, + stderr_buffered = true, + }) + return job_id +end + +function M.make(args) + local args = args or {} + local makeprg = vim.opt.makeprg:get() + local cmd = vim.split(vim.fn.expandcmd(makeprg), ' ') + table.foreach(args, function(_, v) table.insert(cmd, v) end) + return M.jobstart(cmd) +end + +function M.sh(cmd) + local cmd = {vim.env.SHELL, '-c', cmd} + return M.jobstart(cmd) +end + +return M |