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 v0.28.0 incompatiblity with windows bash.exe - Command failed #330

Open
ttk opened this issue Nov 13, 2021 · 7 comments
Open

fzf v0.28.0 incompatiblity with windows bash.exe - Command failed #330

ttk opened this issue Nov 13, 2021 · 7 comments

Comments

@ttk
Copy link

ttk commented Nov 13, 2021

fzf version 0.28.0 introduced a new change where $SHELL is used instead of cmd.exe by default.

For kubectx for windows, using msys2 bash.exe, the following error occurs:
[Command failed: C:\Programs\Bin\kubectx.exe]

This is because bash.exe doesn't recognize that path, but cmd.exe does. This problem doesn't occur in powershell, or cmd.exe.

The workaround is to set the env var SHELL=cmd prior to running kubectx. I setup an alias for this:

alias kx='SHELL=cmd kubectx'

I'm wondering maybe this env variable should be automatically set via kubectx if it detects it's running in windows?

@ahmetb
Copy link
Owner

ahmetb commented Nov 13, 2021

That's a weird issue. Mostly because we (and other tools) trust fzf to do the right thing.

Furthermore, we're planning to allow customizing the picker tool to something other than "fzf", and such customizations wouldn’t carry to similar other tools like "sk" well.

Is there a reason why $SHELL is already not set properly (like it is on Linux/Mac) by your msys2? Can't you just set it on your .bashrc?

Since this is a rather subtle issue, I am inclined to not fix it in this tool but rather expect the environment to do right thing.

If msys2 can't render properly and needs SHELL=cmd, I think that's not kubectx's issue. Maybe fzf or msys bash should fix it. Sorry if I misinterpreted, feel free to correct me.

@ttk
Copy link
Author

ttk commented Nov 13, 2021

Yeah, it's a strange one. My shell env var is properly set to SHELL=/usr/bin/bash, so it doesn't make sense to change that in my .bashrc file. The problem occurs because kubectx sees the command as the native windows path C:\Programs\Bin\kubectx.exe and passes that on to fzf via FZF_DEFAULT_COMMAND=C:\Programs\Bin\kubectx.exe, but then fzf runs it in the bash shell, as per the SHELL env var, which doesn't work.

So basically kubectx needs to give a hint to fzf to run the command without a shell (ideally), but apparently isn't supported a far as I can tell from the fzf source code, which I think is the crux of the problem.

Is there any reason why fzf needs to run kubectx in the context of a shell? Perhaps the fzf project needs to add a new environment variable such as FZF_DISABLE_SHELL? Another option is to simply unset SHELL environment variable prior to running fzf, and fzf will simply default back to the default shell on each system, which I think should work?

msys2 bash.exe:
SHELL="" FZF_DEFAULT_COMMAND=C:\\Programs\\Bin\\kubectx.exe fzf works
FZF_DEFAULT_COMMAND=C:\\Programs\\Bin\\kubectx.exe fzf does not work

@ahmetb
Copy link
Owner

ahmetb commented Dec 27, 2021

Is there any reason why fzf needs to run kubectx in the context of a shell?

We don't. We directly run it:

cmd := exec.Command("fzf", "--ansi", "--no-preview")
However since you're on mingw/cygwin environments, it is very likely that these things trap syscalls and manipulate them.

I'm inclined to not fix this as it might further cause compat issues in edge cases (admittedly this itself is definitely a rare scenario I haven't heard so far).

@mloskot
Copy link

mloskot commented Apr 13, 2023

I'm using Git Bash from Git for Windows 2.40.0

$ echo $SHELL
/usr/bin/bash

and I found that the original workaround suggested by @ttk does not work for me, so instead of this

alias kx='SHELL=cmd kubectx'

the following alias works

alias kx='SHELL= kubectx'

kubectx --version
0.9.4
fzf --version
0.39.0 (2023040)

By the way, this workaround solves #382

@vonhutrong
Copy link

Thanks @mloskot!
It also works for kubens:
alias kn='SHELL= kubens'

@mklauer
Copy link

mklauer commented Oct 22, 2024

@vonhutrong For me the workaround for kubens is not working. What versions du you use? Mine are

kubens --version
0.9.5
fzf --version
0.53.0 (c4a9ccd)

@vonhutrong
Copy link

@mklauer Sorry for kubens I couldn't get its version.

$ kubens --version
error: unrecognized flag "--version"
USAGE:
  kubens                    : list the namespaces in the current context
  kubens <NAME>             : change the active namespace of current context
  kubens -                  : switch to the previous namespace in this context
  kubens -c, --current      : show the current namespace
  kubens -h,--help          : show this message

$ fzf --version
0.53.0 (c4a9ccd)

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

No branches or pull requests

5 participants