Skip to content

Commit

Permalink
Merge pull request #131 from uga-rosa/job
Browse files Browse the repository at this point in the history
Synchronous external command execution independent of shell
  • Loading branch information
tani authored Apr 10, 2024
2 parents b44407a + cd443b5 commit 2ae7300
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
6 changes: 2 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,10 @@ jobs:
- name: Clone vim-jetpack
uses: actions/checkout@v3

- uses: ilammy/msvc-dev-cmd@v1
- name: Install Lua
uses: leafo/gh-actions-lua@v10
if: ${{ contains(matrix.os, 'windows') }}
run: |
Invoke-WebRequest -Uri https://joedf.ahkscript.org/LuaBuilds/hdata/lua-5.4.4_Win64_bin.zip -OutFile .\Lua.zip
Expand-Archive .\Lua.zip C:\Lua
Add-Content $env:GITHUB_PATH C:\Lua

- name: Install vim-themis
uses: actions/checkout@v3
Expand Down
23 changes: 18 additions & 5 deletions plugin/jetpack.vim
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,10 @@ if has('nvim')
\ 'on_exit': { _, st -> st != 0 ? execute("echoerr '`'.join(a:cmd, ' ').'`:'.join(buf, '')") : a:cb(join(buf, '')) }
\ })
endfunction

function! jetpack#system(cmd) abort
return a:cmd->split(" ")->system()
endfunction
else
function! jetpack#jobstart(cmd, cb) abort
let buf = []
Expand All @@ -171,6 +175,15 @@ else
\ 'exit_cb': function('jetpack#nvim_exit_cb', [a:cmd, buf, a:cb])
\ })
endfunction

function! jetpack#system(cmd) abort
let buf = []
let job = job_start(a:cmd, {
\ 'out_cb': { _, data -> extend(buf, split(data, "\n")) }
\})
call jetpack#jobwait([job], 0)
return buf->join("\n")
endfunction
endif

function! jetpack#initialize_buffer() abort
Expand Down Expand Up @@ -235,8 +248,8 @@ function! jetpack#clean_plugins() abort
continue
endif
if isdirectory(pkg.path)
call system(printf('git -C %s reset --hard', pkg.path))
let branch = trim(system(printf('git -C %s rev-parse --abbrev-ref %s', pkg.path, pkg.commit)))
call jetpack#system(printf('git -C %s reset --hard', pkg.path))
let branch = trim(jetpack#system(printf('git -C %s rev-parse --abbrev-ref %s', pkg.path, pkg.commit)))
if v:shell_error && !empty(pkg.commit)
call delete(pkg.path, 'rf')
continue
Expand Down Expand Up @@ -356,7 +369,7 @@ function! jetpack#download_plugins() abort
call add(jobs, job)
call jetpack#jobwait(jobs, g:jetpack_njobs)
else
let pkg.output = join(map(cmds, { _, cmd -> system(cmd) }), "\n")
let pkg.output = join(map(cmds, { _, cmd -> jetpack#system(cmd) }), "\n")
call add(pkg.status, status)
endif
endfor
Expand All @@ -378,7 +391,7 @@ function! jetpack#switch_plugins() abort
else
call add(pkg.status, s:status.switched)
endif
call system(printf('git -C %s checkout %s', pkg.path, pkg.commit))
call jetpack#system(printf('git -C %s checkout %s', pkg.path, pkg.commit))
endfor
endfunction

Expand All @@ -395,7 +408,7 @@ function! jetpack#postupdate_plugins() abort
if pkg.do =~# '^:'
execute pkg.do
else
call system(pkg.do)
call jetpack#system(pkg.do)
endif
endif
call chdir(pwd)
Expand Down

0 comments on commit 2ae7300

Please sign in to comment.