Add MSYS2 support as a vim plugin#1677
Conversation
Add &shellcmdflag and TERM environment variable treatment. - Make &shellcmdflag `/C` when &shell turns into `cmd.exe` - Delete %TERM% environment variable before fzf execution
|
junegunn/fzf.vim uses fzf#shellescape function. But when it calls this function, &shell is not changed to So I changed shell default value &shell to |
|
@janlazo Hi, can you take a look at this? |
|
|
||
| function! fzf#shellescape(arg, ...) | ||
| let shell = get(a:000, 0, &shell) | ||
| let shell = get(a:000, 0, s:is_win ? 'cmd.exe' : &shell) |
There was a problem hiding this comment.
Is this for fzf#wrap only? fzf#run calls s:use_sh to set the shell.
There was a problem hiding this comment.
It is for external program such as junegunn/fzf.vim's vim script which seemingly calls this function before fzf#run execution.
There was a problem hiding this comment.
If you're doing this, go all the way and don't check &shell in this function. Change all invocations of fzf#shellescape within the context of fzf#run to pass &shell. Then, change this line to
let shell = get(a:000, 0, s:is_win ? 'cmd.exe' : 'sh')
There was a problem hiding this comment.
I'm sorry but I can't get what exactly means to add &shell for all invocations of fzf#shellescape.
Could you tell me what aim is laid here, or what problems exist if I don't do that.
In my opinion, since s:use_sh have already replaces &shell to sh or cmd.exe,
there are not so much differences regardless of whether I do that or not.
There was a problem hiding this comment.
Idea is to not set the shell in s:use_sh on Windows in the future, similar to what vim-plug does, because there are many shell option combinations to consider depending on the OS and editor. vim-plug passes &shell to fzf#shellescape when it needs to run a shell command with the user's &shell.
Perhaps, it's too much to do it all in this PR. fzf supported cmd.exe on Windows so doing it halfway (ie. hardcode the default fallback shell to cmd.exe for fzf#shellescape) is fine for now.
There was a problem hiding this comment.
I partially introduced your suggestion at ca770ec for now.
|
This is ok for a first step since you set |
Ubuntu xenial has Vim 7.4. Neovim 0.2.1 bumped its 'v:version' to 800. Neovim 0.2.2 is in Ubuntu bionic and Debian sid. Define commands outside of feature folds. 8.1.1210+ includes the +user_commands feature. Update termguicolor restrictions. Require Neovim v0.3.2+. neovim/neovim@98eaf60 Require Vim v8.1.0839+ with +vcon feature on Windows. vim/vim@f58d81a Unset $TERM in GUIs for fzf on Windows Workaround for junegunn/fzf#1677 (comment) Set nvim defaults in vimrc shared.vim should have shared defaults only. Reorder features in Vim 8.1.x.
| let [shell, shellslash, shellcmdflag] = [&shell, &shellslash, &shellcmdflag] | ||
| if s:is_win | ||
| set shell=cmd.exe | ||
| set shellcmdflag=/c |
There was a problem hiding this comment.
Setting shell options have too many edge cases on Windows because there are 3 incompatible shells to work with and fzf's Vim plugin supports neovim. Like vim-plug, don't set any shell options on Windows.
There was a problem hiding this comment.
Not setting shell options here will take a lot of work so consider Neovim's default shell options here and call it a day.
let &shellcmdflag = has('nvim') ? '/s /c' : '/c'There was a problem hiding this comment.
Thank you for your advice.
I applied it at abde451.
This funcion's behavior is controlled by only if it is Windows or not. So there is no need to check &shell.
|
Wait for junegunn/vim-plug#913 to be merged to vim-plug and then be ported to fzf. Then, rebase your branch so that it can be merged. |
|
I got it. Thank you for your review. |
|
junegunn/vim-plug#913 is backported now, and I've resolved the conflict. Is everything okay? |
| return map([ | ||
| \ '@echo off', | ||
| \ 'setlocal enabledelayedexpansion'] | ||
| \ + (has('gui_running') ? ['set TERM= > nul'] : []) |
There was a problem hiding this comment.
Should port this over to vim-plug.
|
Yes. It's safe to merge but we can wait for @msr1k to verify. Concern in junegunn/vim-plug#913 is unicode and msys2/mingw/cygwin allows unicode. |
|
Tested it on a Windows VM today. It works with my config before and after switching the shell to bash. It's good to go, at least for English users. |
Add &shellcmdflag and TERM environment variable treatment.
/Cwhen &shell turns intocmd.exeOn MSYS2 environment, vim is typically configured as follows:
Since this plugin does not change &shellcmdflag while it replaces &shell with cmd.exe,
vim on MSYS2 environment cannot start fzf properly.
(It try to do
cmd.exe -c something...but it should becmd.exe /C something....)And at the time of starting cmd.exe %TERM% is no longer needed.
So delete this environment variable in the batch file to be executed.