|
3 | 3 | " Maintainer: skywind3000 (at) gmail.com, 2016, 2017, 2018, 2019, 2020
|
4 | 4 | " Homepage: http://www.vim.org/scripts/script.php?script_id=5431
|
5 | 5 | "
|
6 |
| -" Last Modified: 2020/03/23 13:18 |
| 6 | +" Last Modified: 2020/03/25 02:40 |
7 | 7 | "
|
8 | 8 | " Run shell command in background and output to quickfix:
|
9 | 9 | " :AsyncRun[!] [options] {cmd} ...
|
@@ -238,6 +238,18 @@ function! s:chdir(path)
|
238 | 238 | silent execute cmd . ' '. fnameescape(a:path)
|
239 | 239 | endfunc
|
240 | 240 |
|
| 241 | +" safe shell escape for neovim |
| 242 | +function! s:shellescape(path) |
| 243 | + if s:asyncrun_windows == 0 |
| 244 | + return shellescape(a:path) |
| 245 | + endif |
| 246 | + let hr = shellescape(a:path) |
| 247 | + if &ssl != 0 |
| 248 | + let hr = s:StringReplace(hr, "'", '"') |
| 249 | + endif |
| 250 | + return hr |
| 251 | +endfunc |
| 252 | + |
241 | 253 | " save/restore view
|
242 | 254 | function! s:save_restore_view(mode)
|
243 | 255 | if a:mode == 0
|
@@ -663,7 +675,7 @@ function! s:AsyncRun_Job_Start(cmd)
|
663 | 675 | if s:async_nvim == 0
|
664 | 676 | let l:args += [l:tmp]
|
665 | 677 | else
|
666 |
| - let l:args = shellescape(l:tmp) |
| 678 | + let l:args = s:shellescape(l:tmp) |
667 | 679 | endif
|
668 | 680 | endif
|
669 | 681 | elseif type(a:cmd) == 3
|
@@ -1094,7 +1106,7 @@ function! s:terminal_open(opts)
|
1094 | 1106 | if get(a:opts, 'safe', get(g:, 'asyncrun_term_safe', 0)) != 0
|
1095 | 1107 | let command = s:ScriptWrite(command, 0)
|
1096 | 1108 | if stridx(command, ' ') >= 0
|
1097 |
| - let command = shellescape(command) |
| 1109 | + let command = s:shellescape(command) |
1098 | 1110 | endif
|
1099 | 1111 | let shell = 0
|
1100 | 1112 | endif
|
@@ -1397,7 +1409,7 @@ function! s:run(opts)
|
1397 | 1409 | call s:ErrorMsg("not find wsl in your system")
|
1398 | 1410 | return
|
1399 | 1411 | endif
|
1400 |
| - let cmd = shellescape(substitute(tt, '\\', '\/', 'g')) |
| 1412 | + let cmd = s:shellescape(substitute(tt, '\\', '\/', 'g')) |
1401 | 1413 | let dist = get(l:opts, 'dist', get(g:, 'asyncrun_dist', ''))
|
1402 | 1414 | if dist != ''
|
1403 | 1415 | let cmd = cmd . ' -d ' . dist
|
@@ -1521,9 +1533,9 @@ function! s:run(opts)
|
1521 | 1533 | let l:makesave = &l:makeprg
|
1522 | 1534 | let l:script = s:ScriptWrite(l:command, 0)
|
1523 | 1535 | if s:asyncrun_windows != 0
|
1524 |
| - let &l:makeprg = shellescape(l:script) |
| 1536 | + let &l:makeprg = s:shellescape(l:script) |
1525 | 1537 | else
|
1526 |
| - let &l:makeprg = 'source '. shellescape(l:script) |
| 1538 | + let &l:makeprg = 'source '. s:shellescape(l:script) |
1527 | 1539 | endif
|
1528 | 1540 | let l:efm1 = &g:efm
|
1529 | 1541 | let l:efm2 = &l:efm
|
@@ -1624,17 +1636,17 @@ function! s:run(opts)
|
1624 | 1636 | let $VIM_COMMAND = l:command
|
1625 | 1637 | let l:command = script . ' ' . l:command
|
1626 | 1638 | if s:asyncrun_windows
|
1627 |
| - let ccc = shellescape(s:ScriptWrite(l:command, 0)) |
| 1639 | + let ccc = s:shellescape(s:ScriptWrite(l:command, 0)) |
1628 | 1640 | silent exec '!start /b cmd /C '. ccc
|
1629 | 1641 | else
|
1630 | 1642 | call system(l:command . ' &')
|
1631 | 1643 | endif
|
1632 | 1644 | elseif s:asyncrun_windows
|
1633 | 1645 | if l:mode == 4
|
1634 |
| - let l:ccc = shellescape(s:ScriptWrite(l:command, 1)) |
| 1646 | + let l:ccc = s:shellescape(s:ScriptWrite(l:command, 1)) |
1635 | 1647 | silent exec '!start cmd /C '. l:ccc
|
1636 | 1648 | else
|
1637 |
| - let l:ccc = shellescape(s:ScriptWrite(l:command, 0)) |
| 1649 | + let l:ccc = s:shellescape(s:ScriptWrite(l:command, 0)) |
1638 | 1650 | silent exec '!start /b cmd /C '. l:ccc
|
1639 | 1651 | endif
|
1640 | 1652 | redraw
|
@@ -1833,7 +1845,7 @@ endfunc
|
1833 | 1845 | " asyncrun - version
|
1834 | 1846 | "----------------------------------------------------------------------
|
1835 | 1847 | function! asyncrun#version()
|
1836 |
| - return '2.6.9' |
| 1848 | + return '2.7.0' |
1837 | 1849 | endfunc
|
1838 | 1850 |
|
1839 | 1851 |
|
@@ -1898,7 +1910,7 @@ function! s:program_msys(opts)
|
1898 | 1910 | let bash = s:StringReplace(bash, '/', "\\")
|
1899 | 1911 | let path = asyncrun#path_win2unix(fnamemodify(script, ':p'), mount)
|
1900 | 1912 | let flag = ' --login ' . (get(a:opts, 'inter', '')? '-i' : '')
|
1901 |
| - let text = shellescape(bash) . flag . ' "' . path . '"' |
| 1913 | + let text = s:shellescape(bash) . flag . ' "' . path . '"' |
1902 | 1914 | let lines += ['call ' . text . "\r"]
|
1903 | 1915 | call writefile(lines, tmpname)
|
1904 | 1916 | let command = a:opts.cmd
|
|
0 commit comments