mirror of
https://github.com/Llewellynvdm/fzf.git
synced 2024-11-25 22:27:41 +00:00
[vim] Use cmd.exe in Windows (#785)
This commit is contained in:
parent
45faad7e04
commit
42a2371d26
@ -80,7 +80,13 @@ function! s:shellesc(arg)
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:escape(path)
|
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
|
endfunction
|
||||||
|
|
||||||
" Upgrade legacy options
|
" Upgrade legacy options
|
||||||
@ -234,7 +240,15 @@ endfunction
|
|||||||
function! fzf#run(...) abort
|
function! fzf#run(...) abort
|
||||||
try
|
try
|
||||||
let oshell = &shell
|
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"'))
|
if has('nvim') && len(filter(range(1, bufnr('$')), 'bufname(v:val) =~# ";#FZF"'))
|
||||||
call s:warn('FZF is already running!')
|
call s:warn('FZF is already running!')
|
||||||
return []
|
return []
|
||||||
@ -251,7 +265,7 @@ try
|
|||||||
if !has_key(dict, 'source') && !empty($FZF_DEFAULT_COMMAND)
|
if !has_key(dict, 'source') && !empty($FZF_DEFAULT_COMMAND)
|
||||||
let temps.source = tempname()
|
let temps.source = tempname()
|
||||||
call writefile(split($FZF_DEFAULT_COMMAND, "\n"), temps.source)
|
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
|
endif
|
||||||
|
|
||||||
if has_key(dict, 'source')
|
if has_key(dict, 'source')
|
||||||
@ -281,6 +295,7 @@ try
|
|||||||
return lines
|
return lines
|
||||||
finally
|
finally
|
||||||
let &shell = oshell
|
let &shell = oshell
|
||||||
|
let &shellslash = useshellslash
|
||||||
endtry
|
endtry
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
@ -353,7 +368,11 @@ function! s:xterm_launcher()
|
|||||||
\ &columns, &lines/2, getwinposx(), getwinposy())
|
\ &columns, &lines/2, getwinposx(), getwinposy())
|
||||||
endfunction
|
endfunction
|
||||||
unlet! s:launcher
|
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, ...)
|
function! s:exit_handler(code, command, ...)
|
||||||
if a:code == 130
|
if a:code == 130
|
||||||
@ -370,12 +389,17 @@ endfunction
|
|||||||
|
|
||||||
function! s:execute(dict, command, temps) abort
|
function! s:execute(dict, command, temps) abort
|
||||||
call s:pushd(a:dict)
|
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'), '%#')
|
let escaped = escape(substitute(a:command, '\n', '\\n', 'g'), '%#')
|
||||||
if has('gui_running')
|
if has('gui_running')
|
||||||
let Launcher = get(a:dict, 'launcher', get(g:, 'Fzf_launcher', get(g:, 'fzf_launcher', s:launcher)))
|
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 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
|
else
|
||||||
let command = escaped
|
let command = escaped
|
||||||
endif
|
endif
|
||||||
|
Loading…
Reference in New Issue
Block a user