Use chcp only if sed is in PATH

This commit is contained in:
Jan Edmund Lazo 2019-10-13 08:47:30 -04:00
parent 849b76be90
commit c4896c3873
No known key found for this signature in database
GPG Key ID: 64915E6E9F735B15

View File

@ -353,14 +353,16 @@ if s:is_win
" Copied from fzf " Copied from fzf
function! s:wrap_cmds(cmds) function! s:wrap_cmds(cmds)
let use_chcp = executable('sed')
return map([ return map([
\ '@echo off', \ '@echo off',
\ 'setlocal enabledelayedexpansion', \ 'setlocal enabledelayedexpansion']
\ 'for /f "tokens=*" %%a in (''chcp'') do for %%b in (%%a) do set origchcp=%%b', \ + (use_chcp ? [
\ 'chcp 65001 > nul' \ 'for /f "usebackq" %%a in (`chcp ^| sed "s/[^0-9]//gp"`) do set origchcp=%%a',
\ ] \ 'chcp 65001 > nul'] : [])
\ + (type(a:cmds) == type([]) ? a:cmds : [a:cmds]) \ + (type(a:cmds) == type([]) ? a:cmds : [a:cmds])
\ + ['chcp !origchcp! > nul', 'endlocal'], \ + (use_chcp ? ['chcp !origchcp! > nul'] : [])
\ + ['endlocal'],
\ 'v:val."\r"') \ 'v:val."\r"')
endfunction endfunction