summaryrefslogtreecommitdiffstats
path: root/plugin
diff options
context:
space:
mode:
authorJan Edmund Lazo <janlazo@users.noreply.github.com>2016-12-31 21:48:15 -0500
committerJunegunn Choi <junegunn.c@gmail.com>2017-01-01 11:48:15 +0900
commit42a2371d264b4f9b33d0e14847766c49b045df53 (patch)
treecfb9d3cf5119a71024ec48da7f7853133c67aca4 /plugin
parent45faad7e0439adfc8551d69e8f4b9bd65169fabc (diff)
[vim] Use cmd.exe in Windows (#785)
Diffstat (limited to 'plugin')
-rw-r--r--plugin/fzf.vim36
1 files changed, 30 insertions, 6 deletions
diff --git a/plugin/fzf.vim b/plugin/fzf.vim
index 2574a0fc..a873a0ce 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