From 359ce90b9b37442974fd3ccd9279493d85efb3af Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Wed, 11 Dec 2019 08:28:49 -0500 Subject: [PATCH] Encode batchfile in current codepage. (#913) Changing chcp breaks cmd.exe if switching from multi-byte to 65001. cmd.exe depends on codepage to parse batchfile so batchfile cannot have unicode characters. Target powershell if unicode support is required. User should fix their terminal font to display unicode characters. Terminal programs can only use Wide String APIs. For Vim, this requires +multi_byte feature and `set encoding=utf-8` in the user's vimrc. Neovim always defaults to `set encoding=utf-8`. https://dev.to/mattn/please-stop-hack-chcp-65001-27db --- plug.vim | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/plug.vim b/plug.vim index adf802d..92fea62 100644 --- a/plug.vim +++ b/plug.vim @@ -182,6 +182,11 @@ function! s:define_commands() \ && (&shell =~# 'cmd\.exe' || &shell =~# 'powershell\.exe') return s:err('vim-plug does not support shell, ' . &shell . ', when shellslash is set.') endif + if !has('nvim') + \ && (has('win32') || has('win32unix')) + \ && (!has('multi_byte') || !has('iconv')) + return s:err('Vim needs +iconv, +multi_byte features on Windows to run shell commands.') + endif command! -nargs=* -bar -bang -complete=customlist,s:names PlugInstall call s:install(0, []) command! -nargs=* -bar -bang -complete=customlist,s:names PlugUpdate call s:update(0, []) command! -nargs=0 -bar -bang PlugClean call s:clean(0) @@ -395,18 +400,14 @@ if s:is_win endfunction " Copied from fzf + let s:codepage = libcallnr('kernel32.dll', 'GetACP', 0) function! s:wrap_cmds(cmds) - let use_chcp = executable('sed') return map([ \ '@echo off', \ 'setlocal enabledelayedexpansion'] - \ + (use_chcp ? [ - \ '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]) - \ + (use_chcp ? ['chcp !origchcp! > nul'] : []) \ + ['endlocal'], - \ 'v:val."\r"') + \ printf('iconv(v:val."\r", "%s", "cp%d")', &encoding, s:codepage)) endfunction function! s:batchfile(cmd)