mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-02-09 13:40:04 +08:00
fix(job): support cwd option and check executable
This commit is contained in:
parent
6f180c243f
commit
d4a6d1fae4
@ -23,10 +23,13 @@ local function new_job_obj(id, handle, opt, state)
|
|||||||
return jobobj
|
return jobobj
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- @param cmd string|table<string> Spawns {cmd} as a job.
|
||||||
|
--- @param opts table job options
|
||||||
|
--- @return integer # jobid if job run successfully.
|
||||||
|
--- jobid: if job run successfully
|
||||||
|
--- 0: if type of cmd is wrong
|
||||||
|
--- -1: if cmd[1] is not executable
|
||||||
function M.start(cmd, opts)
|
function M.start(cmd, opts)
|
||||||
local stdin = uv.new_pipe()
|
|
||||||
local stdout = uv.new_pipe()
|
|
||||||
local stderr = uv.new_pipe()
|
|
||||||
local command = ''
|
local command = ''
|
||||||
local argv = {}
|
local argv = {}
|
||||||
if type(cmd) == 'string' then
|
if type(cmd) == 'string' then
|
||||||
@ -41,12 +44,20 @@ function M.start(cmd, opts)
|
|||||||
table.insert(argv, cmd)
|
table.insert(argv, cmd)
|
||||||
elseif type(cmd) == 'table' then
|
elseif type(cmd) == 'table' then
|
||||||
command = cmd[1]
|
command = cmd[1]
|
||||||
|
if vim.fn.executable(command) == 0 then return -1 end
|
||||||
argv = vim.list_slice(cmd, 2)
|
argv = vim.list_slice(cmd, 2)
|
||||||
|
else
|
||||||
|
return 0
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local stdin = uv.new_pipe()
|
||||||
|
local stdout = uv.new_pipe()
|
||||||
|
local stderr = uv.new_pipe()
|
||||||
|
|
||||||
local opt = {
|
local opt = {
|
||||||
stdio = { stdin, stdout, stderr },
|
stdio = { stdin, stdout, stderr },
|
||||||
args = argv,
|
args = argv,
|
||||||
|
cwd = opts.cwd or nil
|
||||||
}
|
}
|
||||||
_jobid = _jobid + 1
|
_jobid = _jobid + 1
|
||||||
local current_id = _jobid
|
local current_id = _jobid
|
||||||
|
Loading…
Reference in New Issue
Block a user