Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues 1432 #3002

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
6 changes: 5 additions & 1 deletion plugin/fzf.vim
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ 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.
let s:is_win_cmd = s:is_win && !exists('$SHELL')
if s:is_win && &shellslash
set noshellslash
let s:base_dir = expand('<sfile>:h:h')
Expand Down Expand Up @@ -484,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 ? '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'))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we still shellescape (not fzf#shellescape) temps.input for safety?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The expression is getting a bit too complicated. How about splitting it into if-else statements?

if !s:is_win
  let source_command = ...
elseif exists('$SHELL')
  " Git bash
  let source_command = ...
else
  " cmd.exe
  let source_command = ...
end

else
throw 'Invalid source type'
endif
Expand Down