Skip to content

Commit a9906c7

Browse files
msr1kjunegunn
authored andcommitted
Add MSYS2 support as a vim plugin (#1677)
* Add MSYS2 support as a vim plugin Add &shellcmdflag and TERM environment variable treatment. - Make &shellcmdflag `/C` when &shell turns into `cmd.exe` - Delete %TERM% environment variable before fzf execution * Change shellescape default value depending on s:is_win flag * Make TERM environment empty only when gui is running * Stop checking &shell in fzf#shellescape function This funcion's behavior is controlled by only if it is Windows or not. So there is no need to check &shell. * Take neovim into consideration when to set shellcmdflag * Add &shellxquote control
1 parent 9fefe08 commit a9906c7

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

plugin/fzf.vim

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ if s:is_win
5454
return map([
5555
\ '@echo off',
5656
\ 'setlocal enabledelayedexpansion']
57+
\ + (has('gui_running') ? ['set TERM= > nul'] : [])
5758
\ + (type(a:cmds) == type([]) ? a:cmds : [a:cmds])
5859
\ + ['endlocal'],
5960
\ printf('iconv(v:val."\r", "%s", "cp%d")', &encoding, s:codepage))
@@ -79,7 +80,7 @@ function! s:shellesc_cmd(arg)
7980
endfunction
8081

8182
function! fzf#shellescape(arg, ...)
82-
let shell = get(a:000, 0, &shell)
83+
let shell = get(a:000, 0, s:is_win ? 'cmd.exe' : 'sh')
8384
if shell =~# 'cmd.exe$'
8485
return s:shellesc_cmd(a:arg)
8586
endif
@@ -338,19 +339,21 @@ function! fzf#wrap(...)
338339
endfunction
339340

340341
function! s:use_sh()
341-
let [shell, shellslash] = [&shell, &shellslash]
342+
let [shell, shellslash, shellcmdflag, shellxquote] = [&shell, &shellslash, &shellcmdflag, &shellxquote]
342343
if s:is_win
343344
set shell=cmd.exe
344345
set noshellslash
346+
let &shellcmdflag = has('nvim') ? '/s /c' : '/c'
347+
let &shellxquote = has('nvim') ? '"' : '('
345348
else
346349
set shell=sh
347350
endif
348-
return [shell, shellslash]
351+
return [shell, shellslash, shellcmdflag, shellxquote]
349352
endfunction
350353

351354
function! fzf#run(...) abort
352355
try
353-
let [shell, shellslash] = s:use_sh()
356+
let [shell, shellslash, shellcmdflag, shellxquote] = s:use_sh()
354357

355358
let dict = exists('a:1') ? s:upgrade(a:1) : {}
356359
let temps = { 'result': s:fzf_tempname() }
@@ -420,7 +423,7 @@ try
420423
call s:callback(dict, lines)
421424
return lines
422425
finally
423-
let [&shell, &shellslash] = [shell, shellslash]
426+
let [&shell, &shellslash, &shellcmdflag, &shellxquote] = [shell, shellslash, shellcmdflag, shellxquote]
424427
endtry
425428
endfunction
426429

0 commit comments

Comments
 (0)