I'm trying to get fzf to use rg --files as its command for searching, but can't seem to get it to use the $FZF_DEFAULT_COMMAND environment variable, as described in the docs.

I use fish as my shell, and in my config.fish I have set FZF_DEFAULT_COMMAND rg --files. If I echo $FZF_DEFAULT_COMMANDin my shell, I getrg --files`, so fish is definitely aware of it.

However, when I call fzf it doesn't use this command (for example, it shows gitignored files, such as build outputs etc, but if I just call rg --files, these aren't shown).

The man page for fzf says: "On *nix systems, fzf runs the command with sh -c, so make sure that it's POSIX-compliant". However, if I run sh -c "echo $FZF_DEFAULT_COMMAND, I get rg --files.

Clearly this env var isn't available in the right place, but I'm at a bit of a loss to know how to set it properly. Any help appreciated

  • 3
    Is FZF_DEFAULT_COMMAND exported as an environment variable? You can tell by running env and seeing if it's present in the output. You can export it via the -x flag to set, e.g. set -gx FZF_DEFAULT_COMMAND ... Dec 20, 2021 at 19:22
  • That fixed it, thanks :D Dec 20, 2021 at 21:32
  • Also note that when you did sh -c "echo $FZF_DEFAULT_COMMAND", that interpolated the variable in Fish. You would need sh -c 'echo $FZF_DEFAULT_COMMAND' or sh -c "echo \$FZF_DEFAULT_COMMAND" to pass it to sh properly. That was likely throwing you off a bit as well. Now that you have it exported, it will show with either version. Dec 21, 2021 at 16:02


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.