Skip to content

Commit 4f18713

Browse files
committed
Encode batchfile in current codepage.
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
1 parent e6ed2e5 commit 4f18713

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

plug.vim

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,11 @@ function! s:define_commands()
182182
\ && (&shell =~# 'cmd\.exe' || &shell =~# 'powershell\.exe')
183183
return s:err('vim-plug does not support shell, ' . &shell . ', when shellslash is set.')
184184
endif
185+
if !has('nvim')
186+
\ && (has('win32') || has('win32unix'))
187+
\ && (!has('multi_byte') || !has('iconv'))
188+
return s:err('Vim needs +iconv, +multi_byte features on Windows to run shell commands.')
189+
endif
185190
command! -nargs=* -bar -bang -complete=customlist,s:names PlugInstall call s:install(<bang>0, [<f-args>])
186191
command! -nargs=* -bar -bang -complete=customlist,s:names PlugUpdate call s:update(<bang>0, [<f-args>])
187192
command! -nargs=0 -bar -bang PlugClean call s:clean(<bang>0)
@@ -395,18 +400,14 @@ if s:is_win
395400
endfunction
396401

397402
" Copied from fzf
403+
let s:codepage = libcallnr('kernel32.dll', 'GetACP', 0)
398404
function! s:wrap_cmds(cmds)
399-
let use_chcp = executable('sed')
400405
return map([
401406
\ '@echo off',
402407
\ 'setlocal enabledelayedexpansion']
403-
\ + (use_chcp ? [
404-
\ 'for /f "usebackq" %%a in (`chcp ^| sed "s/[^0-9]//gp"`) do set origchcp=%%a',
405-
\ 'chcp 65001 > nul'] : [])
406408
\ + (type(a:cmds) == type([]) ? a:cmds : [a:cmds])
407-
\ + (use_chcp ? ['chcp !origchcp! > nul'] : [])
408409
\ + ['endlocal'],
409-
\ 'v:val."\r"')
410+
\ printf('iconv(v:val."\r", "%s", "cp%d")', &encoding, s:codepage))
410411
endfunction
411412

412413
function! s:batchfile(cmd)

0 commit comments

Comments
 (0)