Skip to content

Conversation

@msr1k
Copy link
Contributor

@msr1k msr1k commented Aug 31, 2019

Add &shellcmdflag and TERM environment variable treatment.

  • Make &shellcmdflag /C when &shell turns into cmd.exe
  • Delete %TERM% environment variable before fzf execution

On MSYS2 environment, vim is typically configured as follows:

  • &shell: bash
  • &shellcmdflag: -c
  • $TERM(%TERM%): xterm or something

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 be cmd.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.

msr1k added 2 commits August 31, 2019 18:59
Add &shellcmdflag and TERM environment variable treatment.

- Make &shellcmdflag `/C` when &shell turns into `cmd.exe`
- Delete %TERM% environment variable before fzf execution
@msr1k
Copy link
Contributor Author

msr1k commented Aug 31, 2019

junegunn/fzf.vim uses fzf#shellescape function.

But when it calls this function, &shell is not changed to cmd.exe
and shellescaping is executed not for cmd.exe though it is eventually passed to cmd.exe.

So I changed shell default value &shell to cmd.exe when s:is_win is true at c95d52f.

@junegunn
Copy link
Owner

junegunn commented Sep 3, 2019

@janlazo Hi, can you take a look at this?

plugin/fzf.vim Outdated

function! fzf#shellescape(arg, ...)
let shell = get(a:000, 0, &shell)
let shell = get(a:000, 0, s:is_win ? 'cmd.exe' : &shell)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this for fzf#wrap only? fzf#run calls s:use_sh to set the shell.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is for external program such as junegunn/fzf.vim's vim script which seemingly calls this function before fzf#run execution.

Copy link
Contributor

@janlazo janlazo Sep 21, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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')

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I partially introduced your suggestion at ca770ec for now.

@janlazo
Copy link
Contributor

janlazo commented Sep 3, 2019

This is ok for a first step since you set shellcmdflag but to support custom shells, junegunn/vim-plug#856 and junegunn/vim-plug#860 should be ported over.

janlazo added a commit to janlazo/dotvim8 that referenced this pull request Sep 3, 2019
janlazo added a commit to janlazo/dotvim8 that referenced this pull request Sep 16, 2019
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.
plugin/fzf.vim Outdated
let [shell, shellslash, shellcmdflag] = [&shell, &shellslash, &shellcmdflag]
if s:is_win
set shell=cmd.exe
set shellcmdflag=/c
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor

@janlazo janlazo Sep 23, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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'

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your advice.
I applied it at abde451.

@janlazo
Copy link
Contributor

janlazo commented Dec 7, 2019

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.

@msr1k
Copy link
Contributor Author

msr1k commented Dec 9, 2019

I got it. Thank you for your review.

@junegunn
Copy link
Owner

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'] : [])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should port this over to vim-plug.

@janlazo
Copy link
Contributor

janlazo commented Dec 12, 2019

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.

@junegunn junegunn merged commit a9906c7 into junegunn:master Dec 15, 2019
@junegunn
Copy link
Owner

I'm going to merge this as I want to push out a new release with it. Thanks @msr1k and @janlazo

@janlazo
Copy link
Contributor

janlazo commented Dec 15, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants