~ajpaon/quickrun.nvim

a87c72b1705ffaf090fa2f0dcdf38d91f3102f11 — Andrew Paon 2 years ago 5f459aa
execute executable files directly
1 files changed, 22 insertions(+), 2 deletions(-)

M lua/quickrun.lua
M lua/quickrun.lua => lua/quickrun.lua +22 -2
@@ 1,3 1,5 @@
local Job = require'plenary.job'

local M = {}

local ft_commands = {


@@ 18,6 20,18 @@ function destroy_qr_buffer()
  buf = nil
end

function is_executable(file)
  local ret
  Job:new({
    command = 'test',
    args = { '-x', file },
    on_exit = function(_, rv)
      ret = rv == 0
    end
  }):sync()
  return ret
end

function M.quickrun()
  local current_buf = vim.api.nvim_get_current_buf()
  local should_create = current_buf ~= buf


@@ 26,7 40,14 @@ function M.quickrun()
    destroy_qr_buffer()
  end

  local cmd = ft_commands[vim.bo.filetype]
  local filename = vim.fn.expand('%')

  local cmd
  if is_executable(filename) then
    cmd = './%'
  else
    cmd = ft_commands[vim.bo.filetype]
  end

  if not cmd then
    return


@@ 38,7 59,6 @@ function M.quickrun()
  end

  create_qr_buffer(cmd)

end

return M