mirror of
https://github.com/junegunn/vim-plug.git
synced 2024-12-19 02:25:35 -07:00
Use chcp only if sed is in PATH (#891)
chcp parsing is fragile because of the system locale. There's no convenient way to parse out the codepage value without regex just by relying on cmd.exe builtins and default binaries in PATH. Vim can be used to parse chcp output but it requires an additional `system` per `s:system` and `chcp` can change within the same console so caching the value won't work on the terminal. Powershell supports regex but it has a long startup even with `-NoProfile` so running it when `&shell` is not powershell slows down `:PlugInstall` more.
This commit is contained in:
parent
849b76be90
commit
fcfd5b7e1f
12
plug.vim
12
plug.vim
@ -353,14 +353,16 @@ if s:is_win
|
||||
|
||||
" Copied from fzf
|
||||
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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user