@@ 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