418 words — 2 minutes read

Fuzzy File Finding (and warm fuzzy feelings)

While my day job is managing a team of 8 engineers (which means a lot of meetings), I do get to work with the CLI from time to time. As you might know, working on the CLI means navigating deep dirctory structures and working with millions of files. It doesn’t matter if you are into operations or into development, working with directories and files are going to be your bread and butter operations.

For development work, I tend to use on the of the JetBrains IDEs (RubyMine, PyCharm) because I like how the IDEs support you while developping. One of their lovely features is the fuzzy finder when opening files. You start typing letters and the IDE will filter down the files by the letters you typed as they appear in the path or the filename. So typing ser/crop would select the file rails/app/services/openstack/create_openstack_project.rb

Rubymine Example

Selecting files in RubyMine

Today, I happend upon the article Simple Note-Taking with fzf and Vim that introduced me to fzf, the Fuzzy File Finder. Installation (on OS X) is a brew install fzf away. When you run fzf it will by default start to show all files in the current directory and by typing, it will start to filter down the list. Press Return to copy and paste the selected file on the command line. You can also pipe in content to fzf making it handy to filter down long lists of data.

There are a few shortcuts that make life easier: CTRL-T can be used to invoke fzf after having started a command (like vi) to select a filename:

shell example

Selecting files to edit with the 'CTRL-T' shortcut

CTRL-R allows you to select command from the shells history.

I am using Oh My ZSH to configure zsh and it ships with a plugin for fzf. I just had to add the FZF_BASE variable and fzf to the plugins line in ~/.zshrc:

export FZF_BASE=/usr/local/bin/fzf

plugins=(git pyenv osx fzf)

I also had to set my zsh to emacs mode (I was using vi mode, which is non-default) by deleting the line bindkey -v in the .zshrc file to make the CTRL-T and CTRL-R shortcuts work. (I rarely edit my command line entries, and I always got confused by it being in vi mode so no big loss there.

fzf comes with plenty of usage examples in the fzf wiki which I will explore over time.

Another post, How FZF and ripgrep improved my workflow has even more tips and tricks on how to use it.

Jens-Christian Fischer

Maker. Musician