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

fzf.vim cannot be used on Windows inside git-bash shell. [Interested to push a PR, but I need many directions] #1432

Open
4 of 5 tasks
Adnn opened this issue Oct 11, 2022 · 7 comments
Labels

Comments

@Adnn
Copy link

Adnn commented Oct 11, 2022

I have been using fzf successfully under Ubuntu bash shell.

But there are several issues when trying to use in with git-bash shell on Windows 10.

edit: Using Neovim version 0.8.0-1210-gd367ed9b2

Without set shell

If I do not set the shell in my init.vim, the shell is:

shell="C:\Program Files\Git\usr\bin\bash.exe"

Then I cannot get any fzf command to execute. E.g.

 :Files

fails with error:

Error detected while processing function fzf#vim#files[15]..94_fzf[1]..94_check_requirements[11]..fzf#exec[31]..function fzf#vim#files[15]..94_fzf[1]..94_check_requirements[11]..fzf#exec:
line 31:
E605: Exception not caught: Failed to run "C:\Users\adnn\AppData\Local\nvim-data\plugged\fzf/bin/fzf --version"

With set shell=cmd

fzf commands :Files and :Rg work, as they show the pop-up window that is searchable. But the preview does not work:

bash: C:UsersadnAppDataLocalNVIM-D~1pluggedfzf.vimbinpreview.sh: No such file or directory

:Buffers does not work at all. There is an error showing in the pop-up window

[Command failed: type ^"C:\Users\adn\AppData\Local\Temp\nvim.0\FCdV6q\4^"]


I would be interested to address these issues, but I never worked with vim script, nor this project sources, so I would need directions.
I am most interested to address the first case (without setting a shell, which then uses git's bash.exe). From the error, I suppose the problem is that bash fails to execute fzf - -version because the absolute path is starting with C:\Users, which is not a valid git-bash path.

Any pointer where this path is generated in the plugin code?

@Adnn
Copy link
Author

Adnn commented Oct 12, 2022

I created the PR above #1434.
This addresses the case of shell=cmd issue with the preview pane.

I am happy to get feedback and rework the PR to get it accepted.

There is a PR 3002 in fzf repository to address the problem with :Buffers not working at all.

@3N4N
Copy link

3N4N commented Oct 15, 2022

@junegunn there is another similar problem. preview.sh isn't found in non-wsl vim. I think the checking for if the session is in WSL is wrong, unless I'm mistaken to assume s:is_wsl_bash says if current session is in bash. This small change fixes it. See :h WSL for explanation.

diff --git a/autoload/fzf/vim.vim b/autoload/fzf/vim.vim
index 44a17f6d194a..88728af9ae11 100644
--- a/autoload/fzf/vim.vim
+++ b/autoload/fzf/vim.vim
@@ -30,7 +30,7 @@ set cpo&vim
 
 let s:min_version = '0.23.0'
 let s:is_win = has('win32') || has('win64')
-let s:is_wsl_bash = s:is_win && (exepath('bash') =~? 'Windows[/\\]system32[/\\]bash.exe$')
+let s:is_wsl_bash = exists('$WSLENV')
 let s:layout_keys = ['window', 'up', 'down', 'left', 'right']
 let s:bin_dir = expand('<sfile>:p:h:h:h').'/bin/'
 let s:bin = {

@FuDesign2008
Copy link

I met the same question. Is there any progress?

@jtmart
Copy link

jtmart commented Oct 1, 2023

Same issue here @junegunn...do you have any suggestion?

@junegunn
Copy link
Owner

junegunn commented Oct 2, 2023

I'm not a Windows user so I can't be of help. You can help by testing the patch suggested by @Adnn.

@liufuyang
Copy link

liufuyang commented Jan 21, 2024

I had the same problem, cannot get it to work so I end up using powershell for now...

Not sure this helps, but I basically setup the init.vim with output of :shell shell-powershell, something like this:

let &shell = executable('pwsh') ? 'pwsh' : 'powershell'
let &shellcmdflag = '-NoLogo -ExecutionPolicy RemoteSigned -Command [Console]::InputEncoding=[Console]::OutputEncoding=[System.Text.UTF8Encoding]::new();$PSDefaultParameterValues[''Out-File:Encoding'']=''utf8'';'
let &shellredir = '2>&1 | %%{ "$_" } | Out-File %s; exit $LastExitCode'
let &shellpipe  = '2>&1 | %%{ "$_" } | Tee-Object %s; exit $LastExitCode'
set shellquote= shellxquote=

Then in git-bash seems most of the stuff is working, however still could see errors saying something related to boarder from time to time.

@Konfekt
Copy link

Konfekt commented May 19, 2024

Is this still an issue? I check with the latest Fzf master shell and Vim source files, the FZF binary 0.52.1 on Windows 11, and the supplied Vim in Git 2.40. in Windows Terminal and Mintty. Both commands, :Buffers and :Files, work fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants