[vim] Use utf-8 for cmd.exe (#929)

This commit is contained in:
Jan Edmund Lazo 2017-05-30 20:56:01 -04:00 committed by Junegunn Choi
parent 8aab0fc189
commit 669a6fee40

View File

@ -44,10 +44,22 @@ if s:is_win
let &shellslash = shellslash let &shellslash = shellslash
endtry endtry
endfunction endfunction
" Use utf-8 for fzf.vim commands
" Return array of shell commands for cmd.exe
function! s:wrap_cmds(cmds)
return ['@echo off', 'for /f "tokens=4" %%a in (''chcp'') do set origchcp=%%a', 'chcp 65001 > nul'] +
\ (type(a:cmds) == type([]) ? a:cmds : [a:cmds]) +
\ ['chcp %origchcp% > nul']
endfunction
else else
function! s:fzf_call(fn, ...) function! s:fzf_call(fn, ...)
return call(a:fn, a:000) return call(a:fn, a:000)
endfunction endfunction
function! s:wrap_cmds(cmds)
return a:cmds
endfunction
endif endif
function! s:shellesc_cmd(arg) function! s:shellesc_cmd(arg)
@ -352,7 +364,7 @@ try
if !has_key(dict, 'source') && !empty($FZF_DEFAULT_COMMAND) if !has_key(dict, 'source') && !empty($FZF_DEFAULT_COMMAND)
let temps.source = s:fzf_tempname().(s:is_win ? '.bat' : '') let temps.source = s:fzf_tempname().(s:is_win ? '.bat' : '')
call writefile((s:is_win ? ['@echo off'] : []) + split($FZF_DEFAULT_COMMAND, "\n"), temps.source) call writefile(s:wrap_cmds(split($FZF_DEFAULT_COMMAND, "\n")), temps.source)
let dict.source = (empty($SHELL) ? &shell : $SHELL) . (s:is_win ? ' /c ' : ' ') . fzf#shellescape(temps.source) let dict.source = (empty($SHELL) ? &shell : $SHELL) . (s:is_win ? ' /c ' : ' ') . fzf#shellescape(temps.source)
endif endif
@ -510,7 +522,7 @@ function! s:execute(dict, command, use_height, temps) abort
endif endif
if s:is_win if s:is_win
let batchfile = s:fzf_tempname().'.bat' let batchfile = s:fzf_tempname().'.bat'
call writefile(['@echo off', command], batchfile) call writefile(s:wrap_cmds(command), batchfile)
let command = batchfile let command = batchfile
if has('nvim') if has('nvim')
let s:dict = a:dict let s:dict = a:dict