Note: This site is currently "Under construction". I'm migrating to a new version of my site building software. Lots of things are in a state of disrepair as a result (for example, footnote links aren't working). It's all part of the process of building in public. Most things should still be readable though.

Run An External Process Every Time You Save A File In Neovim

  • thing here

  • another thing

Code

vim.api.nvim_create_autocmd("BufWritePost", {
  group = vim.api.nvim_create_augroup("DoTheThingGroup", { clear = true }),
  callback = function() 
    vim.fn.jobstart(
      {"bash", "-c", "sleep 2 && echo Hello"},
      {
        stdout_buffered = true,
        on_stdout = function(_, data) 
          if data then
            print(data)
          end
        end
      }
    )
  end,
})

Code

-- NOTE: This is the original code that uses
-- plenary. Trying it above with the built-in
-- jobstart. If that works, this will be removed

local do_the_thing = function()

  local Job = require 'plenary.job'
  Job:new({
    command = 'bash',
    args = { '-c', 'echo "Doing The Thing"'},
    on_exit = function(job, return_val)
      print(vim.inspect(job:result()))
    end,
  }):start() 

end