summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2019-11-02 14:35:21 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2019-11-02 14:35:21 +0900
commit6390140539caacfb6fd16729d3e6ba4341815b0e (patch)
tree3ecee71bca64b43b94c6cbbfadaebac551005ff6
parent072066c49c01368046cf52c93be5b587aaf10ffe (diff)
[vim/windows] Use chcp only if sed is in PATH
https://github.com/junegunn/vim-plug/pull/891
-rw-r--r--plugin/fzf.vim12
1 files changed, 7 insertions, 5 deletions
diff --git a/plugin/fzf.vim b/plugin/fzf.vim
index ac4c98fd..195bb8b2 100644
--- a/plugin/fzf.vim
+++ b/plugin/fzf.vim
@@ -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