From 669a6fee40a2d946ab35561c47e76d6a2216948c Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Tue, 30 May 2017 20:56:01 -0400 Subject: [PATCH] [vim] Use utf-8 for cmd.exe (#929) --- plugin/fzf.vim | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/plugin/fzf.vim b/plugin/fzf.vim index fbfcd1d..81aff37 100644 --- a/plugin/fzf.vim +++ b/plugin/fzf.vim @@ -44,10 +44,22 @@ if s:is_win let &shellslash = shellslash endtry 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 function! s:fzf_call(fn, ...) return call(a:fn, a:000) endfunction + + function! s:wrap_cmds(cmds) + return a:cmds + endfunction endif function! s:shellesc_cmd(arg) @@ -352,7 +364,7 @@ try if !has_key(dict, 'source') && !empty($FZF_DEFAULT_COMMAND) 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) endif @@ -510,7 +522,7 @@ function! s:execute(dict, command, use_height, temps) abort endif if s:is_win let batchfile = s:fzf_tempname().'.bat' - call writefile(['@echo off', command], batchfile) + call writefile(s:wrap_cmds(command), batchfile) let command = batchfile if has('nvim') let s:dict = a:dict