-
-
Notifications
You must be signed in to change notification settings - Fork 587
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
Fix: Windows preview window logic, including git diff preview #1452
Conversation
autoload/fzf/vim.vim
Outdated
let s:is_defined_win_bash = get(g:, 'fzf_preview_win_bash', '') != '' | ||
if s:is_defined_win_bash | ||
let s:defined_win_bash = split(system('for %A in ("'.g:fzf_preview_win_bash.'") do @echo %~sA'), "\n")[0] | ||
endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I'm not mistaken g:fzf_preview_win_bash
is only for Windows, so should we move this code block to line 45?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should use something like s:bash
or s:bash()
that stores or returns the path to bash to use regardless of the platform and refer to it throughout the code instead of putting conditionals here and there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
function! s:bash()
if exists('s:bash')
return s:bash
endif
" Non-windows
if !s:is_win
let s:bash = 'bash'
elseif exists('g:fzf_preview_win_bash')
" ...
else
" ...
endif
return s:bash
endfunction
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In fact, you can see in line 44
is to determine whether it is running under windows (although only to determine the path of bash, but this path in other environments will not happen, so it should be safe), I changed line 45
to this because in the case of the windows environment has been determined, if you call c:\windows\ system32\bash.exe
to use, in the original if
only has ('nvim')
will lead to path errors (because c:\windows\system32\bash.exe
actually requires the path parameters need to be wsl in the format, that is, else contained in the windows format will be amended to /mnt/ blabla...
This format, so I made this if
, if s:is_defined_win_bash
judgment holds and is not custom c:\windows\system32\bash.exe
case, we will continue to use the path under the windows rule. (This is also a defensive if
on my part, as I ask in the do that if you want to customize bash, make sure the custom bash supports the path to the windows rule as an argument)
It's worth mentioning again that the operations here are based on the windows environment if
on line 44
, so there should be no conflict (at least in my tests so far)
and for the s:bash
:
You're right, and I know I should, but as I mentioned above, I made a lot of poor if else
because I wanted to make sure everywhere I could that it wouldn't interfere with running on other platforms besides windows.
Of course, if make a method is necessary, then I cound find some time to make it right ~ : )
And also, obviously my English is very poor, I hope you can understand what I mean
I'm not a Windows user, and it's really hard for me to understand all the different problems from different setups. So let me clarify a few things.
|
@junegunn |
No hurry, take your time. |
…w option for Windows user(not wsl)
@junegunn
And here's something new. Let's say u use nvim on cmd or powershell, or nvim-qt directly. And u installed WSL,the env's default bash will be the linux-like bash, Ok the usual preview(e.g. If u use vim on cmd or powershell, or gvim directly. And u installed WSL, then the usual preview will working but the diff preview won't, here's less problem than nvim because of the For all the situations, if u didn't install WSL, That will always occur error, of course, that is because the env can not find bash, the solution is also very simple, download the required bash and the accompanying tools, add the env variables. Here only add the Then let's take a look at the new code. I've separated out a few variables, but I've also tried to make sure that it only affects the logic of the Windows environment. To make it easier to add different regex paths in the future I've extracted the linux-like bash and added another global variable so that users(who knows exactly what they're doing) could directly define whether the bash they are using is linux-like or not, but of course, the new variables will not affect the non-Windows env, no matter how the user defines them. Here's the new code's test:
Windows:
Linux:
Mac:
For Windows: Sorry I force-pushed, I feel 1 commit is better to read. |
autoload/fzf/vim.vim
Outdated
if has('nvim') | ||
if !s:is_wsl_bash |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So we no longer need to differentiate between neovim and vim?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes through my tests, we just need to handle the path correctly.
autoload/fzf/vim.vim
Outdated
@@ -28,22 28,54 @@ set cpo&vim | |||
" Common | |||
" ------------------------------------------------------------------ | |||
|
|||
function! s:get_if_linux_like_bash() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can there be a better way to determine the property of the given bash? For example, I wonder if there's a command that we can run to see the behavior of the bash.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something like bash -c 'ls /mnt/*'
maybe? (and see if it returns one of /mnt/[A-Z]
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something like
bash -c 'ls /mnt/*'
maybe? (and see if it returns one of/mnt/[A-Z]
)
This is a good idea, it seems to avoid the maintenance of new and different types of bash in the future.
@junegunn This time I didn't force push because I need to do more test after daily work, and also, your opinion. Windows:
Linux:
Mac:
|
autoload/fzf/vim.vim
Outdated
@@ -633,6 649,7 @@ function! fzf#vim#gitfiles(args, ...) | |||
return s:warn('Not in git repo') | |||
endif | |||
let prefix = 'git -C ' . fzf#shellescape(root) . ' ' | |||
let diff_prefix = s:is_linux_like_bash ? 'git -C ' . substitute(root, '^\([A-Z]\):', '/mnt/\L\1', '') . ' ' : prefix |
There was a problem hiding this comment.
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
(or fzf#shellescape
) the /mnt/...
path in case it contains whitespaces?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, shellescape
function of Vim is probably not the right choice because this is a Windows vim.
There was a problem hiding this comment.
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
(orfzf#shellescape
) the/mnt/...
path in case it contains whitespaces?
Understand your point, I'll find a way to deal with it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did some test with create some whitespaces git repo.
escape(root, ' ')
or substitute(root, '\s', '\\ ', 'g')
both worked.
root path with whitespace could be solved, but if there's some whitespaces in filename, I haven't found a solution in fzf.vim
yet, because I remember this seems need to be solved from the fzf
side, which I met it before when I was using it in Arch, I don't think we should use whitespace in the filename so I didn't thought it's a issus : )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if there's some whitespaces in filename, I haven't found a solution in
fzf.vim
yet
I'm not sure what you mean by that. {}
evaluates to an escaped string, so this works as expected.
echo 'hello' > 'foo bar'
echo 'foo bar' | fzf --preview 'cat {}'
I don't think we should use whitespace in the filename
I agree, but file paths with whitespaces do exist (Program Files
for example) and we can't just ignore that. Anyway, I believe escape(root, ' ')
should be good enough for 99% of the cases.
Let me take this over and finish it up hopefully with some improvements.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I did know there's some paths like Program Files
, so I said escape(root, ' ')
worked.
What I mean for the whitespaces in the filename is this, for example on Arch:
If there's whitespaces in the filename, the preview command occur something, but I think we shouldn't use those filenames, so I don't think that's an issus.
And do I need to modify this line to
let diff_prefix = s:is_linux_like_bash ? 'git -C ' . escape(substitute(root, '^\([A-Z]\):', '/mnt/\L\1', ''), ' ') . ' ' : prefix
then rebase to one commit and force push?
And I want to add this to the doc for the fzf_preview_win_bash
:
We do not recommend including special characters such as whitespaces in the path if it's not the windows system's native path
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#1200 should have fixed it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, that doesn't address the issue in :GF?
variant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah the :GitFiles?
needs this too, I'll see what I could do or maybe I could just look forward to your update : )
Then still the question I mentioned above, do I need force push to one commit for updating diff_prefix
line and doc, or u take all over~
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah the
:GitFiles?
needs this too
We'll address this in a separate issue/PR.
* Look for the usual location of Git bash by default. No need to manually set a variable. * Rename `g:fzf_preview_win_bash` to `g:fzf_preview_bash` and use it also on non-Windows environment * Replace \ to / even on Git bash, because cmd.exe was not properly passing backslashes in the argument * This fixes `GF?` not running `preview.sh` > /usr/bin/bash: C:UsersADMINI~1VIM~1pluggedfzf.vimbinpreview.sh: command not found * Remove --bash-test flag from preview.sh * `ls /mnt/[A-Z]` should suffice and is less likely to have issues with cmd.exe argument passing mechanism C:\Users\Administrator>cd "c:\Program Files\Git\bin" c:\Program Files\Git\bin>bash -c "ls C:\\Users" ls: cannot access 'C:Users': No such file or directory c:\Program Files\Git\bin>bash -c "ls C:/Users" Administrator 'All Users' Default 'Default User' Public desktop.ini
I have updated your branch, please see the commit message of 8c29937 for details, and let me know if it doesn't work as expected. One thing I wasn't so sure about was the way you tested "linux-like"-ness of the bash using |
I think we are exec the bash script directly so we don't need
It seems that you still prefer At last I push a new commit to fix two lines, I found no problems elsewhere and I have tested the items I tested before and they all worked ~ sorry for forced pushing because the test env is too much to see the wrong file : ( |
This I'm not so sure about. According to
No problem, will merge this, thanks! |
Ah, that's where I couldn't see and consider, I'll check it later. Anyway, thank you very much for some advice and suggestions, I have learned a lot : ) |
Merged, thanks for the work! |
* upstr-master: Add :Jumps (junegunn#710) Require the latest fzf [fzf#vim#grep[2]] Deprecate has_column argument Add :RG command and fzf#vim#grep2 function Update documentation and comments [[B]Commits] Support arguments for git-log (junegunn#1455) Fix: Windows preview window logic, including git diff preview (junegunn#1452) Update RG example fix: GFiles is ignoring args (junegunn#1447) [GFiles] Use ls-files --deduplicate only on git 2.31 or above Add support for nushell (junegunn#1300) Make :GFiles work with "unusual" filenames (junegunn#1200) Fix ctags language force for C (junegunn#1425) Update g:fzf_preview_window example Revert "Add Sponsor Labels action" Add Sponsor Labels action
Fix preview window problems for Windows user.
I generally use Arch for development, but recently I also started using WSL, sometimes I don't want to open WSL, so I just open nvim in terminal and use it, I'm kind of a heavy user of
fzf.vim
, this plugin is really good. However, I found that the preview window reported various errors when using it directly in Windows (e.g.nvim-qt
);I looked through the documentation and some other PRs, but I found that some of the solutions could cause another problem while solving one, so I tried to fix some of the problems and added an option to use other bash directly ( git bash, for example).
I've tried to minimize the impact on users using other environments, and I use WSL and Linux myself, so I understand the importance of stability.
Here's what I've tested, and even if it doesn't merge successfully, I hope this will help people who are having the same problem as me.
All with or without
delta
,ag
.All neovim use
packer
.All vim use
plug
.Windows:
neovim
andvim x64
incmd
andpowershell
nvim-qt
andgVim x64
neovim
andvim
in WSL -ubuntu
andArch
Git bash
with vimgVim x32
can not work properly because it can't access the bash underC:\system32
, some people say 32bit can only access the files underC:\Windows\Sysnative
but I don't have the environment to test it for now, replace it in the configuration file to other bash (such asgit bash
:let g:fzf_preview_win_bash='C:\path\to\Git\bin\bash.exe'
) can work properly.Linux:
Mac: