Skip to content

Commit 849b76b

Browse files
authored
Fix chcp parsing for the current codepage (#888)
Relying on delimiters or token positions is fragile. Last value of 'chcp' output is always a number.
1 parent ff97806 commit 849b76b

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

plug.vim

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -353,9 +353,15 @@ if s:is_win
353353

354354
" Copied from fzf
355355
function! s:wrap_cmds(cmds)
356-
return map(['@echo off','setlocal enabledelayedexpansion','for /f "delims=: tokens=2" %%a in (''chcp'') do set origchcp=%%a','set origchcp=!origchcp: =!','chcp 65001 > nul'] +
357-
\ (type(a:cmds) == type([]) ? a:cmds : [a:cmds]) +
358-
\ ['chcp !origchcp! > nul','setlocal disabledelayedexpansion'],'v:val."\r"')
356+
return map([
357+
\ '@echo off',
358+
\ 'setlocal enabledelayedexpansion',
359+
\ 'for /f "tokens=*" %%a in (''chcp'') do for %%b in (%%a) do set origchcp=%%b',
360+
\ 'chcp 65001 > nul'
361+
\ ]
362+
\ + (type(a:cmds) == type([]) ? a:cmds : [a:cmds])
363+
\ + ['chcp !origchcp! > nul', 'endlocal'],
364+
\ 'v:val."\r"')
359365
endfunction
360366

361367
function! s:batchfile(cmd)

0 commit comments

Comments
 (0)