0

fzf --preview 'cat {}' gives me a two-pane terminal window of (left) a fzf fuzzy search for files and (right) a preview of said files.

When called, it starts out showing me /Users/tomnorway/Downloads, regardless of my current directory. I'd like to write a command that only finds files/folders within my current directory (recursively). Having read through man fzf to the best of my ability, I find no way to specify that. Does anyone have any advice?

TomNorway
  • 2,584
  • 1
  • 19
  • 26
  • That's strange - I believe the default behaviour of fzf is indeed to search the current directory... what do you get if you do `echo $FZF_DEFAULT_OPTS` and `echo $FZF_DEFAULT_COMMAND`? – mattb Aug 14 '21 at 08:29
  • Interesting! Well, I get nothing returned for the first one, and `fd . /Users/tomnorway` for the second. Any thoughts? I am definitely by default getting a list of directories outside of my current directory (I navigated a few steps into a git repo before calling `fzf --preview 'cat {}'`). I can then type the git repo name and it does find that. – TomNorway Aug 14 '21 at 12:31
  • Actually I think this is the intended default: `export FZF_DEFAULT_COMMAND='fd --type f'` see https://github.com/junegunn/fzf (see under the 'Environmental variables' heading) – mattb Aug 14 '21 at 13:12

1 Answers1

3

From you response in the comments, given that the output of echo $FZF_DEFAULT_COMMAND is:

fd . /Users/tomnorway

You should go into your ~/.bashrc and replace the line:

export FZF_DEFAULT_COMMAND='fd . /Users/tomnorway'

with:

export FZF_DEFAULT_COMMAND='fd --type f'

Bonus

I also have an answer for if you want fzf to search a dedicated shortlist of directories (e.g. Docs, Downloads, Pics, Vids, Admin, MyDir... etc.) regardless of where you are in the filesystem (https://stackoverflow.com/a/67019648/14467607). I like this because it effectively means I can find any file at any time (but without cluttering the fzf list with thousands of random files from various installations in my home directory).

mattb
  • 2,787
  • 2
  • 6
  • 20