Directory zooming with Fzf and Fasd

08 May 2017


flick photo by ebergcanada shared under a Creative Commons (BY-NC-ND) license

If you are working on many projects in many different directories of your computer, it is often difficult to remember the full path name of the directory that contains the files that you need. However, if you are already using a terminal window to navigate your file system, then there are some tools that can make this task easier.

To take advantage of the "directory zooming" technique that I present in this post, you will need to install two programs: Fzf and Fasd. To learn more about these programs, you should visit their sites and read their extensive documentation. For now, you should know that Fzf is a "fuzzy finder" that makes it easy for you to select matching items from a list. Alternatively, the Fasd program stores information about the files and directories that you frequently access, allowing you to quickly navigate to them.

Now, we can put these two programs together so that Fasd stores the directories you most commonly access and Fzf acts as a filter for those directories, helping you to change into the one whose name you only partially remember. In the following code segment, the t() function — that is short for "to" — first gets a list of all the directories you have recently and frequently visited and then passes that program's output to Fzf.

t() {
  fasdlist=$( fasd -d -l -r $1 | \
    fzf --query="$1 " --select-1 --exit-0 --height=25% --reverse --tac --no-sort --cycle) &&
    cd "$fasdlist"
}

Now, if I type t paper in my terminal window, I would see the following output. At this point it would be possible to type in partial matches of directory names (e.g., "avmf") and then immediately zoom to the directory that contains the source code for a paper that my colleague and I recently published (McMinn & Kapfhammer, 2016).

$ t paper
> paper
  14/14
> /home/gkapfham/working/research/writing/softwaretesting/mutation/sen2017-paper
  /home/gkapfham/working/writing/paperreviews
  /home/gkapfham/working/research/writing/softwaretesting/databases/icsme2016-mspredictr-paper
  /home/gkapfham/working/research/writing/softwaretesting/databases/icsme2016-mrstudyrtool-paper
  /home/gkapfham/working/research/writing/softwaretesting/responsiveweb/redecheck-journal-paper
  /home/gkapfham/working/research/writing/softwaretesting/datageneration/avmframework-paper
  /home/gkapfham/working/www/gkapfham/download/research/papers
  /home/gkapfham/working/research/writing/softwaretesting/databases/icsme2016_satool_paper

What are the ways in which you navigate your file system? If you are a researcher, writer, or software developer who regularly uses the terminal window, I would also appreciate your feedback on the approach that I suggested in this post. So, please contact me to share your insights!

Enjoy this post? If so, please read, SEED Interview with Timothy Tsai, my most recent article.

Categories

References

Like my work? Support it!