Skip to content

Commit ba9a223

Browse files
author
skywind3000
committed
follow &shellslash option on windows.
1 parent 3e5feef commit ba9a223

File tree

1 file changed

+23
-11
lines changed

1 file changed

+23
-11
lines changed

plugin/asyncrun.vim

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
" Maintainer: skywind3000 (at) gmail.com, 2016, 2017, 2018, 2019, 2020
44
" Homepage: http://www.vim.org/scripts/script.php?script_id=5431
55
"
6-
" Last Modified: 2020/03/23 13:18
6+
" Last Modified: 2020/03/25 02:40
77
"
88
" Run shell command in background and output to quickfix:
99
" :AsyncRun[!] [options] {cmd} ...
@@ -238,6 +238,18 @@ function! s:chdir(path)
238238
silent execute cmd . ' '. fnameescape(a:path)
239239
endfunc
240240

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+
241253
" save/restore view
242254
function! s:save_restore_view(mode)
243255
if a:mode == 0
@@ -663,7 +675,7 @@ function! s:AsyncRun_Job_Start(cmd)
663675
if s:async_nvim == 0
664676
let l:args += [l:tmp]
665677
else
666-
let l:args = shellescape(l:tmp)
678+
let l:args = s:shellescape(l:tmp)
667679
endif
668680
endif
669681
elseif type(a:cmd) == 3
@@ -1094,7 +1106,7 @@ function! s:terminal_open(opts)
10941106
if get(a:opts, 'safe', get(g:, 'asyncrun_term_safe', 0)) != 0
10951107
let command = s:ScriptWrite(command, 0)
10961108
if stridx(command, ' ') >= 0
1097-
let command = shellescape(command)
1109+
let command = s:shellescape(command)
10981110
endif
10991111
let shell = 0
11001112
endif
@@ -1397,7 +1409,7 @@ function! s:run(opts)
13971409
call s:ErrorMsg("not find wsl in your system")
13981410
return
13991411
endif
1400-
let cmd = shellescape(substitute(tt, '\\', '\/', 'g'))
1412+
let cmd = s:shellescape(substitute(tt, '\\', '\/', 'g'))
14011413
let dist = get(l:opts, 'dist', get(g:, 'asyncrun_dist', ''))
14021414
if dist != ''
14031415
let cmd = cmd . ' -d ' . dist
@@ -1521,9 +1533,9 @@ function! s:run(opts)
15211533
let l:makesave = &l:makeprg
15221534
let l:script = s:ScriptWrite(l:command, 0)
15231535
if s:asyncrun_windows != 0
1524-
let &l:makeprg = shellescape(l:script)
1536+
let &l:makeprg = s:shellescape(l:script)
15251537
else
1526-
let &l:makeprg = 'source '. shellescape(l:script)
1538+
let &l:makeprg = 'source '. s:shellescape(l:script)
15271539
endif
15281540
let l:efm1 = &g:efm
15291541
let l:efm2 = &l:efm
@@ -1624,17 +1636,17 @@ function! s:run(opts)
16241636
let $VIM_COMMAND = l:command
16251637
let l:command = script . ' ' . l:command
16261638
if s:asyncrun_windows
1627-
let ccc = shellescape(s:ScriptWrite(l:command, 0))
1639+
let ccc = s:shellescape(s:ScriptWrite(l:command, 0))
16281640
silent exec '!start /b cmd /C '. ccc
16291641
else
16301642
call system(l:command . ' &')
16311643
endif
16321644
elseif s:asyncrun_windows
16331645
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))
16351647
silent exec '!start cmd /C '. l:ccc
16361648
else
1637-
let l:ccc = shellescape(s:ScriptWrite(l:command, 0))
1649+
let l:ccc = s:shellescape(s:ScriptWrite(l:command, 0))
16381650
silent exec '!start /b cmd /C '. l:ccc
16391651
endif
16401652
redraw
@@ -1833,7 +1845,7 @@ endfunc
18331845
" asyncrun - version
18341846
"----------------------------------------------------------------------
18351847
function! asyncrun#version()
1836-
return '2.6.9'
1848+
return '2.7.0'
18371849
endfunc
18381850

18391851

@@ -1898,7 +1910,7 @@ function! s:program_msys(opts)
18981910
let bash = s:StringReplace(bash, '/', "\\")
18991911
let path = asyncrun#path_win2unix(fnamemodify(script, ':p'), mount)
19001912
let flag = ' --login ' . (get(a:opts, 'inter', '')? '-i' : '')
1901-
let text = shellescape(bash) . flag . ' "' . path . '"'
1913+
let text = s:shellescape(bash) . flag . ' "' . path . '"'
19021914
let lines += ['call ' . text . "\r"]
19031915
call writefile(lines, tmpname)
19041916
let command = a:opts.cmd

0 commit comments

Comments
 (0)