Support non-batchfile shellescape for cmd.exe
This commit is contained in:
parent
91a643c0ed
commit
b7507c20a4
28
plug.vim
28
plug.vim
|
@ -361,7 +361,7 @@ if s:is_win
|
||||||
function! s:batchfile(cmd)
|
function! s:batchfile(cmd)
|
||||||
let batchfile = tempname().'.bat'
|
let batchfile = tempname().'.bat'
|
||||||
call writefile(s:wrap_cmds(a:cmd), batchfile)
|
call writefile(s:wrap_cmds(a:cmd), batchfile)
|
||||||
let cmd = s:shellesc(batchfile, &shell)
|
let cmd = s:shellesc(batchfile, {'shell': &shell, 'script': 1})
|
||||||
if &shell =~# 'powershell\.exe$'
|
if &shell =~# 'powershell\.exe$'
|
||||||
let cmd = '& ' . cmd
|
let cmd = '& ' . cmd
|
||||||
endif
|
endif
|
||||||
|
@ -1219,7 +1219,7 @@ function! s:spawn(name, cmd, opts)
|
||||||
let job = { 'name': a:name, 'running': 1, 'error': 0, 'lines': [''],
|
let job = { 'name': a:name, 'running': 1, 'error': 0, 'lines': [''],
|
||||||
\ 'new': get(a:opts, 'new', 0) }
|
\ 'new': get(a:opts, 'new', 0) }
|
||||||
let s:jobs[a:name] = job
|
let s:jobs[a:name] = job
|
||||||
let cmd = has_key(a:opts, 'dir') ? s:with_cd(a:cmd, a:opts.dir) : a:cmd
|
let cmd = has_key(a:opts, 'dir') ? s:with_cd(a:cmd, a:opts.dir, 0) : a:cmd
|
||||||
let argv = s:is_win ? ['cmd', '/s', '/c', '"'.cmd.'"'] : ['sh', '-c', cmd]
|
let argv = s:is_win ? ['cmd', '/s', '/c', '"'.cmd.'"'] : ['sh', '-c', cmd]
|
||||||
|
|
||||||
if s:nvim
|
if s:nvim
|
||||||
|
@ -1359,8 +1359,8 @@ while 1 " Without TCO, Vim stack is bound to explode
|
||||||
\ printf('git clone %s %s %s %s 2>&1',
|
\ printf('git clone %s %s %s %s 2>&1',
|
||||||
\ has_tag ? '' : s:clone_opt,
|
\ has_tag ? '' : s:clone_opt,
|
||||||
\ prog,
|
\ prog,
|
||||||
\ s:shellesc(spec.uri),
|
\ s:shellesc(spec.uri, {'script': 0}),
|
||||||
\ s:shellesc(s:trim(spec.dir))), { 'new': 1 })
|
\ s:shellesc(s:trim(spec.dir), {'script': 0})), { 'new': 1 })
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if !s:jobs[name].running
|
if !s:jobs[name].running
|
||||||
|
@ -1987,12 +1987,9 @@ function! s:update_ruby()
|
||||||
EOF
|
EOF
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:shellesc_cmd(arg)
|
function! s:shellesc_cmd(arg, script)
|
||||||
let escaped = substitute(a:arg, '[&|<>()@^]', '^&', 'g')
|
let escaped = substitute(a:arg, '%', (a:script ? '%' : '^') . '&', 'g')
|
||||||
let escaped = substitute(escaped, '%', '%%', 'g')
|
return substitute('"'.escaped.'"', '[&|<>()@^!"]', '^&', 'g')
|
||||||
let escaped = substitute(escaped, '"', '\\^&', 'g')
|
|
||||||
let escaped = substitute(escaped, '\(\\\+\)\(\\^\)', '\1\1\2', 'g')
|
|
||||||
return '^"'.substitute(escaped, '\(\\\+\)$', '\1\1', '').'^"'
|
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:shellesc_ps1(arg)
|
function! s:shellesc_ps1(arg)
|
||||||
|
@ -2000,9 +1997,11 @@ function! s:shellesc_ps1(arg)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:shellesc(arg, ...)
|
function! s:shellesc(arg, ...)
|
||||||
let shell = get(a:000, 0, s:is_win ? 'cmd.exe' : 'sh')
|
let opts = get(a:000, 0, {})
|
||||||
|
let shell = get(opts, 'shell', s:is_win ? 'cmd.exe' : 'sh')
|
||||||
|
let script = get(opts, 'script', 1)
|
||||||
if shell =~# 'cmd\.exe$'
|
if shell =~# 'cmd\.exe$'
|
||||||
return s:shellesc_cmd(a:arg)
|
return s:shellesc_cmd(a:arg, script)
|
||||||
endif
|
endif
|
||||||
if shell =~# 'powershell\.exe$'
|
if shell =~# 'powershell\.exe$'
|
||||||
return s:shellesc_ps1(a:arg)
|
return s:shellesc_ps1(a:arg)
|
||||||
|
@ -2039,8 +2038,9 @@ function! s:format_message(bullet, name, message)
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:with_cd(cmd, dir)
|
function! s:with_cd(cmd, dir, ...)
|
||||||
return printf('cd%s %s && %s', s:is_win ? ' /d' : '', s:shellesc(a:dir), a:cmd)
|
let script = get(a:000, 0, 1)
|
||||||
|
return printf('cd%s %s && %s', s:is_win ? ' /d' : '', s:shellesc(a:dir, {'script': script}), a:cmd)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:system(cmd, ...)
|
function! s:system(cmd, ...)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user