junegunn / fzf.vim

fzf :heart: vim
MIT License
9.51k stars 581 forks source link

[bug] g:fzf_vim.preview_bash forced to always use backlash in windows #1543

Open DanSM-5 opened 1 month ago

DanSM-5 commented 1 month ago

Using GitFiles or other commands that uses the built-in preview.sh script does not work when using (n)vim from git bash interactive shell. You'll see an error in the preview as follows:

/usr/bin/bash: line 1: C:PROGRA~1Gitusrbinbash.exe: command not found

I set g:fzf_vim.preview_bash to C:/Progra~1/Git/bin/bash.exe but the error persisted as if the preview_bash value was being ignored. I found the issue comes from the function s:bash as it does the following:

  let custom_bash = s:conf('preview_bash', '')
  let git_bash = 'C:\Program Files\Git\bin\bash.exe'
  let candidates = filter(s:is_win ? [custom_bash, 'bash', git_bash] : [custom_bash, 'bash'], 'len(v:val)')

  let found = filter(map(copy(candidates), 'exepath(v:val)'), 'len(v:val)')

The exepath(v:val) will expand the path to a windows style path with backlashes. E.g. the following

:echo filter(map(copy(['C:/Progra~1/Git/bin/bash.exe', 'C:/Program Files/Git/bin/bash.exe']), 'exepath(v:val)'), 'len(v:val)')

will return

['C:\Progra~1\Git\bin\bash.exe', 'C:\Program Files\Git\bin\bash.exe']

Which doesn't work when the interactive shell is git bash. If I manually set the value of s:bash with the content of g:fzf_vim.preview_bash as is (forward slash), then the preview script works fine.

Could the behavior of evaluating the path for g:fzf_vim.preview_bash be changed to take the string as is? If not, could it be a separate variable that is taken as is for the bash preview?

Info

fzf --version
0.52.1 (6432f00)