forked from Civitasv/cmake-tools.nvim
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvimux.lua
More file actions
76 lines (60 loc) · 1.87 KB
/
vimux.lua
File metadata and controls
76 lines (60 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
local osys = require("cmake-tools.osys")
local utils = require("cmake-tools.utils")
---@class vimux : executor, runner
local _vimux = {
id = nil,
}
function _vimux.show(opts)
vim.fn.VimuxInspectRunner()
end
function _vimux.close(opts)
vim.fn.VimuxCloseRunner()
end
function _vimux.run(cmd, env_script, env, args, cwd, opts, on_exit, on_output)
local full_cmd = _vimux.prepare_cmd_for_run(cmd, env, args, cwd)
vim.fn.VimuxRunCommand(full_cmd)
if type(on_exit) == "function" then
on_exit(0) -- vimux does not provide exit codes, assume success
end
end
function _vimux.has_active_job(opts)
return false
end
function _vimux.stop(opts)
vim.fn.VimuxSendKeys("C-c")
end
---Check if the executor is installed and can be used
---@return string|boolean
function _vimux.is_installed()
if not vim.fn.exists(":VimuxRunCommand") then
return "Vimux plugin is missing, please install it"
end
return true
end
function _vimux.prepare_cmd_for_run(cmd, env, args, cwd)
local full_cmd = ""
-- Launch form executable's build directory by default
full_cmd = "cd " .. utils.shell_quote(cwd) .. " &&"
if osys.iswin32 then
for k, v in pairs(env) do
full_cmd = full_cmd .. " set " .. k .. "=" .. v .. "&&"
end
else
for k, v in pairs(env) do
full_cmd = full_cmd .. " " .. k .. "=" .. v .. ""
end
end
full_cmd = full_cmd .. " " .. utils.shell_quote(cmd)
if osys.islinux or osys.iswsl or osys.ismac then
full_cmd = " " .. full_cmd -- adding a space in front of the command prevents bash from recording the command in the history (if configured)
end
-- Add args to the cmd
for _, arg in ipairs(args) do
full_cmd = full_cmd .. " " .. utils.shell_quote(arg)
end
if osys.iswin32 then -- wrap in sub process to prevent env vars from being persited
full_cmd = 'cmd /C "' .. full_cmd .. '"'
end
return full_cmd
end
return _vimux