Autocompleting Files, Directories, Processes, and More with fzf
Learn how to use the fzf command and perform autocompletion.
We'll cover the following
Navigating a more complex filesystem like a codebase can be challenging, even with tab completion. The fzf
tool lets us navigate our filesystem, history, and even processes by searching for partial words. It’s a fuzzy finder for our shell.
Unfortunately, fzf
isn’t available through Ubuntu’s package manager. To install fzf
on Ubuntu, we grab its source code from GitHub and run an installer script. The easiest way to do this is to install Git on our Ubuntu machine and use it to clone the source code repository. Git isn’t covered in this course. We’re just going to use it to fetch the fzf
program.
Setting up fzf
First, we use apt
to install the git
package:
$ sudo apt install git
Next, we use git
to download fzf
to the ~/.fzf
directory:
$ git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf
When we use git clone
, we download the current version of the files along with all previous versions. The --depth 1
option tells git
to only grab the current version.
Now, we run the installer:
$ ~/.fzf/install
For your convenience, we’ve already installed fzf
. Time to start using this tool.
Creating directories
First, let’s create a few directories.
$ mkdir -p files/{movies,music,photos,docs/{diagrams,markdown},code/{go,js,elm}}
Now, we use fzf
to navigate to the files/code/elm
directory:
$ `__fzf_cd__`
We type elm
at the prompt, and the result shrinks. The path files/code/elm
fills in. We press “Enter,” and the current working directory changes.
Get hands-on with 1400+ tech skills courses.