Fix chcp parsing for the current codepage

Relying on delimiters or token positions is fragile.
Last value of 'chcp' output is always a number.
This commit is contained in:
Jan Edmund Lazo 2019-09-30 19:59:17 -04:00
parent ff97806e50
commit dacb634bf8
No known key found for this signature in database
GPG Key ID: 64915E6E9F735B15

View File

@ -353,9 +353,15 @@ if s:is_win
" Copied from fzf " Copied from fzf
function! s:wrap_cmds(cmds) function! s:wrap_cmds(cmds)
return map(['@echo off','setlocal enabledelayedexpansion','for /f "delims=: tokens=2" %%a in (''chcp'') do set origchcp=%%a','set origchcp=!origchcp: =!','chcp 65001 > nul'] + return map([
\ (type(a:cmds) == type([]) ? a:cmds : [a:cmds]) + \ '@echo off',
\ ['chcp !origchcp! > nul','setlocal disabledelayedexpansion'],'v:val."\r"') \ 'setlocal enabledelayedexpansion',
\ 'for /f "tokens=*" %%a in (''chcp'') do for %%b in (%%a) do set origchcp=%%b',
\ 'chcp 65001 > nul'
\ ]
\ + (type(a:cmds) == type([]) ? a:cmds : [a:cmds])
\ + ['chcp !origchcp! > nul', 'endlocal'],
\ 'v:val."\r"')
endfunction endfunction
function! s:batchfile(cmd) function! s:batchfile(cmd)