Skip to content

Commit

Permalink
output of chcp was not parsed correctly (#886)
Browse files Browse the repository at this point in the history
* output of chcp was not parsed correctly

On Windows, when wrapping a batch command with the function s:wrap_cmds(),
when calling 'chcp' to get the current code page, the code assumed that
the output was in the format "active code page: XXX" (where XXX is the
code page), whereas the actual output is localized (for instance, in
French, the output would be: "page de code active: XXX").
The parsing of the output relied on that, and this failed for a
message different from "active code page" (i.e., English).

This patch changes the parsing to split the output of chcp on the colon
instead of spaces. Assuming that the output is always in the format
"<localized message>: XXX", regardless of the locale, hopefully, this is
a bit more robust.
  • Loading branch information
gh4w authored and janlazo committed Sep 29, 2019
1 parent 46f843a commit 68b31a4
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions plug.vim
Original file line number Diff line number Diff line change
Expand Up @@ -353,9 +353,9 @@ if s:is_win

" 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'] +
return map(['@echo off','setlocal enabledelayedexpansion','for /f "delims=: tokens=2" %%a in (''chcp'') do set origchcp=%%a','set origchcp=!origchcp: =!','chcp 65001 > nul'] +
\ (type(a:cmds) == type([]) ? a:cmds : [a:cmds]) +
\ ['chcp %origchcp% > nul'], 'v:val."\r"')
\ ['chcp !origchcp! > nul','setlocal disabledelayedexpansion'],'v:val."\r"')
endfunction

function! s:batchfile(cmd)
Expand Down

0 comments on commit 68b31a4

Please sign in to comment.