summary refs log tree commit diff
path: root/.vim/lua/job.lua
diff options
context:
space:
mode:
authorRobert Günzler <r@gnzler.io>2021-07-29 23:39:08 +0200
committerRobert Günzler <r@gnzler.io>2021-07-29 23:40:32 +0200
commit3079e935c793a9aa1831fd165e28636eb7a87dae (patch)
treee832ac6a08ad70c14c01b1eac32ac1b5eec3549f /.vim/lua/job.lua
parentcefbce656c511a3583744ed7735aa71249b73500 (diff)
vim: cleanup config
Diffstat (limited to '')
-rw-r--r--.vim/lua/job.lua45
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