From 43213deb128b1244200199638d9d460aa2f1027e Mon Sep 17 00:00:00 2001 From: msr0210 Date: Sat, 31 Aug 2019 18:59:48 +0900 Subject: [PATCH 1/6] 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 --- plugin/fzf.vim | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/plugin/fzf.vim b/plugin/fzf.vim index 1d1910bef71..11b877d5d51 100644 --- a/plugin/fzf.vim +++ b/plugin/fzf.vim @@ -50,7 +50,7 @@ if s:is_win " Use utf-8 for fzf.vim commands " Return array of shell commands for cmd.exe function! s:wrap_cmds(cmds) - return map(['@echo off', 'for /f "tokens=4" %%a in (''chcp'') do set origchcp=%%a', 'chcp 65001 > nul'] + + return map(['@echo off', 'set TERM= > nul', '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'], 'v:val."\r"') endfunction @@ -334,19 +334,20 @@ function! fzf#wrap(...) endfunction function! s:use_sh() - let [shell, shellslash] = [&shell, &shellslash] + let [shell, shellslash, shellcmdflag] = [&shell, &shellslash, &shellcmdflag] if s:is_win set shell=cmd.exe + set shellcmdflag=/c set noshellslash else set shell=sh endif - return [shell, shellslash] + return [shell, shellslash, shellcmdflag] endfunction function! fzf#run(...) abort try - let [shell, shellslash] = s:use_sh() + let [shell, shellslash, shellcmdflag] = s:use_sh() let dict = exists('a:1') ? s:upgrade(a:1) : {} let temps = { 'result': s:fzf_tempname() } @@ -416,7 +417,7 @@ try call s:callback(dict, lines) return lines finally - let [&shell, &shellslash] = [shell, shellslash] + let [&shell, &shellslash, &shellcmdflag] = [shell, shellslash, shellcmdflag] endtry endfunction From c95d52fa0cbdacecda4dc8c0aaa7d0515f5e18ad Mon Sep 17 00:00:00 2001 From: msr0210 Date: Sun, 1 Sep 2019 06:38:11 +0900 Subject: [PATCH 2/6] Change shellescape default value depending on s:is_win flag --- plugin/fzf.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/fzf.vim b/plugin/fzf.vim index 11b877d5d51..64cc829a7cd 100644 --- a/plugin/fzf.vim +++ b/plugin/fzf.vim @@ -75,7 +75,7 @@ function! s:shellesc_cmd(arg) endfunction function! fzf#shellescape(arg, ...) - let shell = get(a:000, 0, &shell) + let shell = get(a:000, 0, s:is_win ? 'cmd.exe' : &shell) if shell =~# 'cmd.exe$' return s:shellesc_cmd(a:arg) endif From 502432f7a6764362fa03093c0b7491140f8f3ffc Mon Sep 17 00:00:00 2001 From: Masahiro Kasashima Date: Sun, 22 Sep 2019 10:32:14 +0900 Subject: [PATCH 3/6] Make TERM environment empty only when gui is running --- plugin/fzf.vim | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plugin/fzf.vim b/plugin/fzf.vim index 64cc829a7cd..09ee6df4fc7 100644 --- a/plugin/fzf.vim +++ b/plugin/fzf.vim @@ -50,7 +50,9 @@ if s:is_win " Use utf-8 for fzf.vim commands " Return array of shell commands for cmd.exe function! s:wrap_cmds(cmds) - return map(['@echo off', 'set TERM= > nul', 'for /f "tokens=4" %%a in (''chcp'') do set origchcp=%%a', 'chcp 65001 > nul'] + + return map(['@echo off'] + + \ (has('gui_running') ? ['set TERM= > nul'] : []) + + \ ['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'], 'v:val."\r"') endfunction From ca770ec63940fa665a283afc30c92bd3c9ffd9a4 Mon Sep 17 00:00:00 2001 From: Masahiro Kasashima Date: Sun, 22 Sep 2019 11:11:12 +0900 Subject: [PATCH 4/6] 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. --- plugin/fzf.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/fzf.vim b/plugin/fzf.vim index 09ee6df4fc7..4c5f5bad3d0 100644 --- a/plugin/fzf.vim +++ b/plugin/fzf.vim @@ -77,7 +77,7 @@ function! s:shellesc_cmd(arg) endfunction function! fzf#shellescape(arg, ...) - let shell = get(a:000, 0, s:is_win ? 'cmd.exe' : &shell) + let shell = get(a:000, 0, s:is_win ? 'cmd.exe' : 'sh') if shell =~# 'cmd.exe$' return s:shellesc_cmd(a:arg) endif From abde45180f947f5b6f1d3320973d9a7025fc8575 Mon Sep 17 00:00:00 2001 From: Masahiro Kasashima Date: Fri, 27 Sep 2019 06:31:42 +0900 Subject: [PATCH 5/6] Take neovim into consideration when to set shellcmdflag --- plugin/fzf.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/fzf.vim b/plugin/fzf.vim index 4c5f5bad3d0..3d22d7c7abb 100644 --- a/plugin/fzf.vim +++ b/plugin/fzf.vim @@ -339,8 +339,8 @@ function! s:use_sh() let [shell, shellslash, shellcmdflag] = [&shell, &shellslash, &shellcmdflag] if s:is_win set shell=cmd.exe - set shellcmdflag=/c set noshellslash + let &shellcmdflag = has('nvim') ? '/s /c' : '/c' else set shell=sh endif From 637d59fa44eb2763f255b9e43069d7f826b524c7 Mon Sep 17 00:00:00 2001 From: msr0210 Date: Sat, 7 Dec 2019 07:37:55 +0900 Subject: [PATCH 6/6] Add &shellxquote control --- plugin/fzf.vim | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/plugin/fzf.vim b/plugin/fzf.vim index 3d22d7c7abb..d6baca9dd0d 100644 --- a/plugin/fzf.vim +++ b/plugin/fzf.vim @@ -336,20 +336,21 @@ function! fzf#wrap(...) endfunction function! s:use_sh() - let [shell, shellslash, shellcmdflag] = [&shell, &shellslash, &shellcmdflag] + let [shell, shellslash, shellcmdflag, shellxquote] = [&shell, &shellslash, &shellcmdflag, &shellxquote] if s:is_win set shell=cmd.exe set noshellslash let &shellcmdflag = has('nvim') ? '/s /c' : '/c' + let &shellxquote = has('nvim') ? '"' : '(' else set shell=sh endif - return [shell, shellslash, shellcmdflag] + return [shell, shellslash, shellcmdflag, shellxquote] endfunction function! fzf#run(...) abort try - let [shell, shellslash, shellcmdflag] = s:use_sh() + let [shell, shellslash, shellcmdflag, shellxquote] = s:use_sh() let dict = exists('a:1') ? s:upgrade(a:1) : {} let temps = { 'result': s:fzf_tempname() } @@ -419,7 +420,7 @@ try call s:callback(dict, lines) return lines finally - let [&shell, &shellslash, &shellcmdflag] = [shell, shellslash, shellcmdflag] + let [&shell, &shellslash, &shellcmdflag, &shellxquote] = [shell, shellslash, shellcmdflag, shellxquote] endtry endfunction