Add s:batchfile() for creating batchfiles
Outputs a list containing the batchfile filepath and the new command to run the batchfile regardless of the user's shell.
This commit is contained in:
parent
bb12f7998d
commit
91a643c0ed
38
plug.vim
38
plug.vim
|
@ -350,6 +350,23 @@ if s:is_win
|
|||
function! s:is_local_plug(repo)
|
||||
return a:repo =~? '^[a-z]:\|^[%~]'
|
||||
endfunction
|
||||
|
||||
" Copied from fzf
|
||||
function! s:wrap_cmds(cmds)
|
||||
return map(['@echo off', 'for /f "tokens=4" %%a in (''chcp'') do set origchcp=%%a', 'chcp 65001 > nul'] +
|
||||
\ (type(a:cmds) == type([]) ? a:cmds : [a:cmds]) +
|
||||
\ ['chcp %origchcp% > nul'], 'v:val."\r"')
|
||||
endfunction
|
||||
|
||||
function! s:batchfile(cmd)
|
||||
let batchfile = tempname().'.bat'
|
||||
call writefile(s:wrap_cmds(a:cmd), batchfile)
|
||||
let cmd = s:shellesc(batchfile, &shell)
|
||||
if &shell =~# 'powershell\.exe$'
|
||||
let cmd = '& ' . cmd
|
||||
endif
|
||||
return [batchfile, cmd]
|
||||
endfunction
|
||||
else
|
||||
function! s:rtp(spec)
|
||||
return s:dirpath(a:spec.dir . get(a:spec, 'rtp', ''))
|
||||
|
@ -807,12 +824,7 @@ function! s:bang(cmd, ...)
|
|||
" but it won't work on Windows.
|
||||
let cmd = a:0 ? s:with_cd(a:cmd, a:1) : a:cmd
|
||||
if s:is_win
|
||||
let batchfile = tempname().'.bat'
|
||||
call writefile(["@echo off\r", cmd . "\r"], batchfile)
|
||||
let cmd = s:shellesc(batchfile, &shell)
|
||||
if &shell =~# 'powershell\.exe$'
|
||||
let cmd = '& ' . cmd
|
||||
endif
|
||||
let [batchfile, cmd] = s:batchfile(cmd)
|
||||
endif
|
||||
let g:_plug_bang = (s:is_win && has('gui_running') ? 'silent ' : '').'!'.escape(cmd, '#!%')
|
||||
execute "normal! :execute g:_plug_bang\<cr>\<cr>"
|
||||
|
@ -2036,12 +2048,7 @@ function! s:system(cmd, ...)
|
|||
let [sh, shellcmdflag, shrd] = s:chsh(1)
|
||||
let cmd = a:0 > 0 ? s:with_cd(a:cmd, a:1) : a:cmd
|
||||
if s:is_win
|
||||
let batchfile = tempname().'.bat'
|
||||
call writefile(["@echo off\r", cmd . "\r"], batchfile)
|
||||
let cmd = s:shellesc(batchfile, &shell)
|
||||
if &shell =~# 'powershell\.exe$'
|
||||
let cmd = '& ' . cmd
|
||||
endif
|
||||
let [batchfile, cmd] = s:batchfile(cmd)
|
||||
endif
|
||||
return system(cmd)
|
||||
finally
|
||||
|
@ -2373,12 +2380,7 @@ function! s:preview_commit()
|
|||
let [sh, shellcmdflag, shrd] = s:chsh(1)
|
||||
let cmd = 'cd '.s:shellesc(g:plugs[name].dir).' && git show --no-color --pretty=medium '.sha
|
||||
if s:is_win
|
||||
let batchfile = tempname().'.bat'
|
||||
call writefile(["@echo off\r", cmd . "\r"], batchfile)
|
||||
let cmd = s:shellesc(batchfile, &shell)
|
||||
if &shell =~# 'powershell\.exe$'
|
||||
let cmd = '& ' . cmd
|
||||
endif
|
||||
let [batchfile, cmd] = s:batchfile(cmd)
|
||||
endif
|
||||
execute 'silent %!' cmd
|
||||
finally
|
||||
|
|
Loading…
Reference in New Issue
Block a user