junegunn / fzf

:cherry_blossom: A command-line fuzzy finder
https://junegunn.github.io/fzf/
MIT License
63.78k stars 2.37k forks source link

`FZF_DEFAULT_COMMAND` breaks when `SHELL` set to `pwsh` #3296

Open mattcargile opened 1 year ago

mattcargile commented 1 year ago

Info

Problem / Steps to reproduce

When $env:SHELL or $SHELL is set to pwsh -NoLogo on Windows or /usr/bin/pwsh on *nix ( in my case it is RHEL 9 ), usage like

$env:FZF_DEFAULT_COMMAND = 'fd.exe'
fzf

fails with command failed.

I have even tried

$env:SHELL = 'pwsh -NoLogo -NoProfile -ExecutionPolicy Bypass -NonInteractive -InputFormat Text -OutputFormat Text -Command'

on Windows and it still fails.

Workaround

On Windows set $env:SHELL = 'cmd.exe'. On *nix running pwsh, do $env:SHELL = '/usr/bin/bash' or the like.

Workaround Update

On pwsh version 7.3.8, setting $env:SHELL = 'pwsh' does work now. It seems adding parameters will break fzf usage on Windows.

RH-TLagrone commented 11 months ago

@mattcargile I am encountering the same issue. Have you been able to diagnose the underlying mechanism(s)? If not, could you share any promising leads that you think I could build on to troubleshoot myself?

mattcargile commented 11 months ago

@mattcargile I am encountering the same issue. Have you been able to diagnose the underlying mechanism(s)? If not, could you share any promising leads that you think I could build on to troubleshoot myself?

I'm not sure how to debug it unless you understand the fzf source and how it uses that environment variable.

On pwsh version 7.3.8, I did just try setting $env:SHELL = 'pwsh' and it does work. Adding the parameters is what breaks it. Maybe try it without parameters?

RH-TLagrone commented 11 months ago

Ah, that explanation seems likely. I've run into issues with Windows treating things like that as a command name (i.e. just the resolvable name of an executable) rather than a command invocation/expression (i.e. to be parsed into a command to execute and arguments to pass to it).

Does fzf have any mechanism to specify a default command for shell invocations that fzf will take care of parsing/interpreting itself? (analogous to the currently-supported environment variables FZF_DEFAULT_COMMAND, FZF_CTRL_T_COMMAND, etc.)

mattcargile commented 10 months ago

Ah, that explanation seems likely. I've run into issues with Windows treating things like that as a command name (i.e. just the resolvable name of an executable) rather than a command invocation/expression (i.e. to be parsed into a command to execute and arguments to pass to it).

Does fzf have any mechanism to specify a default command for shell invocations that fzf will take care of parsing/interpreting itself? (analogous to the currently-supported environment variables FZF_DEFAULT_COMMAND, FZF_CTRL_T_COMMAND, etc.)

I looked briefly at the README.md and didn't see anything. I might try creating a bat or cmd file as your $env:SHELL to get the features you want?

Additionally, after looking at source, if you have pwsh or powershell in your $env:SHELL the command executed is altered and -NoProfile -Command is added. It doesn't appear like fzf is designed for this particular use case. No matter what, on Windows, at least -c added to your $Env:SHELL.