junegunn / junegunn/fzf.vim

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

Open
#1,543 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Vim Script
Stars
10.3k
Forks
608
Avg merge
5d 8h
Merged PRs (30d)
2

Description

- [x] I have fzf 0.30.0 or above
- [x] I have read through https://github.com/junegunn/fzf.vim/blob/master/README.md
- [x] I have read through https://github.com/junegunn/fzf/blob/master/README-VIM.md
- [x] I have read through the manual page of fzf (`man fzf`)
- [x] I have searched through the existing issues

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:

```bash
/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`](https://github.com/junegunn/fzf.vim/blob/master/autoload/fzf/vim.vim#L49) as it does the following:

```vim
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

```vim
: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

```vim
['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

```bash
fzf --version
0.52.1 (6432f00)
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.