[vim/windows] Use chcp only if sed is in PATH

https://github.com/junegunn/vim-plug/pull/891
This commit is contained in:
Junegunn Choi 2019-11-02 14:35:21 +09:00
parent 072066c49c
commit 6390140539
No known key found for this signature in database
GPG Key ID: 254BC280FEF9C627

View File

@ -50,14 +50,16 @@ if s:is_win
" Use utf-8 for fzf.vim commands
" Return array of shell commands for cmd.exe
function! s:wrap_cmds(cmds)
let use_chcp = executable('sed')
return map([
\ '@echo off',
\ 'setlocal enabledelayedexpansion',
\ 'for /f "tokens=*" %%a in (''chcp'') do for %%b in (%%a) do set origchcp=%%b',
\ 'chcp 65001 > nul'
\ ]
\ '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])
\ + ['chcp !origchcp! > nul', 'endlocal'],
\ + (use_chcp ? ['chcp !origchcp! > nul'] : [])
\ + ['endlocal'],
\ 'v:val."\r"')
endfunction
else