From 42f48bab41b90d6a37b0732e3b1c722edad68a57 Mon Sep 17 00:00:00 2001 From: Adrien Date: Wed, 12 Oct 2022 16:14:17 +0200 Subject: [PATCH 1/7] WIP: Fix :Buffers. --- plugin/fzf.vim | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugin/fzf.vim b/plugin/fzf.vim index d1da7b7964c..da15b599e8c 100644 --- a/plugin/fzf.vim +++ b/plugin/fzf.vim @@ -484,7 +484,8 @@ try elseif type == 3 let temps.input = s:fzf_tempname() call s:writefile(source, temps.input) - let source_command = (s:is_win ? 'type ' : 'cat ').fzf#shellescape(temps.input) + "let source_command = (s:is_win ? 'type ' : 'cat ').fzf#shellescape(temps.input) + let source_command = 'cat '.substitute(temps.input, '\', '/', 'g') else throw 'Invalid source type' endif From 58a340c91fcddca32f6c5ec6f25425855ea92c87 Mon Sep 17 00:00:00 2001 From: Adrien Date: Wed, 12 Oct 2022 16:56:28 +0200 Subject: [PATCH 2/7] Fix for git-bash by specially detecting it, fix regressiong on cmd.exe. --- plugin/fzf.vim | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/plugin/fzf.vim b/plugin/fzf.vim index da15b599e8c..47bfbe3081e 100644 --- a/plugin/fzf.vim +++ b/plugin/fzf.vim @@ -37,6 +37,9 @@ endif if s:is_win let s:term_marker = '&::FZF' + " This is not bulletproof, but cmd.exe does not have SHELL env var. + let s:is_gitbash = has_key(environ(), 'SHELL') + function! s:fzf_call(fn, ...) let shellslash = &shellslash try @@ -484,8 +487,8 @@ try elseif type == 3 let temps.input = s:fzf_tempname() call s:writefile(source, temps.input) - "let source_command = (s:is_win ? 'type ' : 'cat ').fzf#shellescape(temps.input) - let source_command = 'cat '.substitute(temps.input, '\', '/', 'g') + let source_command = (s:is_win && !s:is_gitbash ? 'type ' : 'cat ') + \.(s:is_gitbash ? substitute(temps.input, '\', '/', 'g') : fzf#shellescape(temps.input)) else throw 'Invalid source type' endif From 1c1fde6cca52875f5cd0666d9bf86a5629f4dd59 Mon Sep 17 00:00:00 2001 From: Adrien Date: Wed, 19 Oct 2022 14:15:50 +0200 Subject: [PATCH 3/7] Revert to the master state at the root of this branch. This reverts commit 42f48bab41b90d6a37b0732e3b1c722edad68a57. --- plugin/fzf.vim | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/plugin/fzf.vim b/plugin/fzf.vim index 47bfbe3081e..d1da7b7964c 100644 --- a/plugin/fzf.vim +++ b/plugin/fzf.vim @@ -37,9 +37,6 @@ endif if s:is_win let s:term_marker = '&::FZF' - " This is not bulletproof, but cmd.exe does not have SHELL env var. - let s:is_gitbash = has_key(environ(), 'SHELL') - function! s:fzf_call(fn, ...) let shellslash = &shellslash try @@ -487,8 +484,7 @@ try elseif type == 3 let temps.input = s:fzf_tempname() call s:writefile(source, temps.input) - let source_command = (s:is_win && !s:is_gitbash ? 'type ' : 'cat ') - \.(s:is_gitbash ? substitute(temps.input, '\', '/', 'g') : fzf#shellescape(temps.input)) + let source_command = (s:is_win ? 'type ' : 'cat ').fzf#shellescape(temps.input) else throw 'Invalid source type' endif From 25df6f33635613bdab0bd8dcb26b267b64ce66fa Mon Sep 17 00:00:00 2001 From: Adrien Date: Wed, 19 Oct 2022 14:19:06 +0200 Subject: [PATCH 4/7] Attempt the proposal to treat git-bash like a Unix shell environment. See: https://github.com/junegunn/fzf/pull/3002#issuecomment-1279891181 --- plugin/fzf.vim | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plugin/fzf.vim b/plugin/fzf.vim index d1da7b7964c..8d097bc9663 100644 --- a/plugin/fzf.vim +++ b/plugin/fzf.vim @@ -26,7 +26,9 @@ if exists('g:loaded_fzf') endif let g:loaded_fzf = 1 -let s:is_win = has('win32') || has('win64') +" On Windows, cmd.exe does not define a `SHELL` env var, whereas git-bash does. +" Treat git-bash environment like a Unix shell. +let s:is_win = has('win32') || has('win64') && !exists('$SHELL') if s:is_win && &shellslash set noshellslash let s:base_dir = expand(':h:h') From ab0ba4f071578c47f46199c9309e71d497805e3f Mon Sep 17 00:00:00 2001 From: Adrien Date: Wed, 19 Oct 2022 14:45:20 +0200 Subject: [PATCH 5/7] Add missing parentheses in is_win condition. --- plugin/fzf.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/fzf.vim b/plugin/fzf.vim index 8d097bc9663..eb2c0ec61bc 100644 --- a/plugin/fzf.vim +++ b/plugin/fzf.vim @@ -28,7 +28,7 @@ let g:loaded_fzf = 1 " On Windows, cmd.exe does not define a `SHELL` env var, whereas git-bash does. " Treat git-bash environment like a Unix shell. -let s:is_win = has('win32') || has('win64') && !exists('$SHELL') +let s:is_win = (has('win32') || has('win64')) && !exists('$SHELL') if s:is_win && &shellslash set noshellslash let s:base_dir = expand(':h:h') From f729a569d3adc907785634ce5436bc18759b1ed1 Mon Sep 17 00:00:00 2001 From: Adrien Date: Wed, 19 Oct 2022 14:50:31 +0200 Subject: [PATCH 6/7] Previous attempts failed. Scope the change more tightly. --- plugin/fzf.vim | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugin/fzf.vim b/plugin/fzf.vim index eb2c0ec61bc..0ca8e8e5514 100644 --- a/plugin/fzf.vim +++ b/plugin/fzf.vim @@ -26,9 +26,9 @@ if exists('g:loaded_fzf') endif let g:loaded_fzf = 1 +let s:is_win = has('win32') || has('win64') " On Windows, cmd.exe does not define a `SHELL` env var, whereas git-bash does. -" Treat git-bash environment like a Unix shell. -let s:is_win = (has('win32') || has('win64')) && !exists('$SHELL') +let s:is_win_cmd = s:is_win && !exists('$SHELL') if s:is_win && &shellslash set noshellslash let s:base_dir = expand(':h:h') @@ -94,7 +94,7 @@ function! s:shellesc_cmd(arg) endfunction function! fzf#shellescape(arg, ...) - let shell = get(a:000, 0, s:is_win ? 'cmd.exe' : 'sh') + let shell = get(a:000, 0, s:is_win_cmd ? 'cmd.exe' : 'sh') if shell =~# 'cmd.exe$' return s:shellesc_cmd(a:arg) endif @@ -486,7 +486,7 @@ try elseif type == 3 let temps.input = s:fzf_tempname() call s:writefile(source, temps.input) - let source_command = (s:is_win ? 'type ' : 'cat ').fzf#shellescape(temps.input) + let source_command = (s:is_win_cmd ? 'type ' : 'cat ').fzf#shellescape(temps.input) else throw 'Invalid source type' endif From 6aa4ed870df0521527a86f7d09e1e40ca0ec30b9 Mon Sep 17 00:00:00 2001 From: Adrien Date: Wed, 19 Oct 2022 15:08:44 +0200 Subject: [PATCH 7/7] Revert shellescape behaviour, explicitly avoid escaping on :Buffers. --- plugin/fzf.vim | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/plugin/fzf.vim b/plugin/fzf.vim index 0ca8e8e5514..3fca9ef8035 100644 --- a/plugin/fzf.vim +++ b/plugin/fzf.vim @@ -94,7 +94,7 @@ function! s:shellesc_cmd(arg) endfunction function! fzf#shellescape(arg, ...) - let shell = get(a:000, 0, s:is_win_cmd ? 'cmd.exe' : 'sh') + let shell = get(a:000, 0, s:is_win ? 'cmd.exe' : 'sh') if shell =~# 'cmd.exe$' return s:shellesc_cmd(a:arg) endif @@ -486,7 +486,9 @@ try elseif type == 3 let temps.input = s:fzf_tempname() call s:writefile(source, temps.input) - let source_command = (s:is_win_cmd ? 'type ' : 'cat ').fzf#shellescape(temps.input) + " Disable shell escape for git bash, as it breaks the command here + let source_command = (s:is_win_cmd ? 'type ' : 'cat ') + \.(!s:is_win || !exists('$SHELL') ? fzf#shellescape(temps.input) : substitute(temps.input, '\', '/', 'g')) else throw 'Invalid source type' endif