From 42a2371d264b4f9b33d0e14847766c49b045df53 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Sat, 31 Dec 2016 21:48:15 -0500 Subject: [PATCH] [vim] Use cmd.exe in Windows (#785) --- plugin/fzf.vim | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/plugin/fzf.vim b/plugin/fzf.vim index 2574a0f..a873a0c 100644 --- a/plugin/fzf.vim +++ b/plugin/fzf.vim @@ -80,7 +80,13 @@ function! s:shellesc(arg) endfunction function! s:escape(path) - return escape(a:path, ' $%#''"\') + let escaped_chars = '$%#''"' + + if has('unix') + let escaped_chars .= ' \' + endif + + return escape(a:path, escaped_chars) endfunction " Upgrade legacy options @@ -234,7 +240,15 @@ endfunction function! fzf#run(...) abort try let oshell = &shell - set shell=sh + let useshellslash = &shellslash + + if has('win32') || has('win64') + set shell=cmd.exe + set shellslash + else + set shell=sh + endif + if has('nvim') && len(filter(range(1, bufnr('$')), 'bufname(v:val) =~# ";#FZF"')) call s:warn('FZF is already running!') return [] @@ -251,7 +265,7 @@ try if !has_key(dict, 'source') && !empty($FZF_DEFAULT_COMMAND) let temps.source = tempname() call writefile(split($FZF_DEFAULT_COMMAND, "\n"), temps.source) - let dict.source = (empty($SHELL) ? 'sh' : $SHELL) . ' ' . s:shellesc(temps.source) + let dict.source = (empty($SHELL) ? &shell : $SHELL) . ' ' . s:shellesc(temps.source) endif if has_key(dict, 'source') @@ -281,6 +295,7 @@ try return lines finally let &shell = oshell + let &shellslash = useshellslash endtry endfunction @@ -353,7 +368,11 @@ function! s:xterm_launcher() \ &columns, &lines/2, getwinposx(), getwinposy()) endfunction unlet! s:launcher -let s:launcher = function('s:xterm_launcher') +if has('win32') || has('win64') + let s:launcher = 'cmd.exe /C %s' +else + let s:launcher = function('s:xterm_launcher') +endif function! s:exit_handler(code, command, ...) if a:code == 130 @@ -370,12 +389,17 @@ endfunction function! s:execute(dict, command, temps) abort call s:pushd(a:dict) - silent! !clear 2> /dev/null + if has('unix') + silent! !clear 2> /dev/null + endif let escaped = escape(substitute(a:command, '\n', '\\n', 'g'), '%#') if has('gui_running') let Launcher = get(a:dict, 'launcher', get(g:, 'Fzf_launcher', get(g:, 'fzf_launcher', s:launcher))) let fmt = type(Launcher) == 2 ? call(Launcher, []) : Launcher - let command = printf(fmt, "'".substitute(escaped, "'", "'\"'\"'", 'g')."'") + if has('unix') + let escaped = "'".substitute(escaped, "'", "'\"'\"'", 'g')."'" + endif + let command = printf(fmt, escaped) else let command = escaped endif