Improve your command-line experience through directory zooming with fzf and fasd

post
developer productivity
software tool
Cool tools can enhance your command-line!
Author

Gregory M. Kapfhammer

Published

2017

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. This post introduces two useful tools!

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. I can now type in partial matches of directory names (e.g., “avmf”) and then “zoom” to the directory that contains the source code for a paper, (McMinn and Kapfhammer 2016) that my colleague and I recently published.

$ t paper
> paper
  14/14
> /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

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!

Get the Gist!
Status Update

Since this blog post was written, I continue to use a wide variety of command-line tools to implement and test software. You can learn more about the tools that I currently used by checking the configuration files in gkapfham/dotfiles!

Return to Blog Post Listing

References

McMinn, Phil, and Gregory M. Kapfhammer. 2016. “AVMf: An Open-Source Framework and Implementation of the Alternating Variable Method.” In Proceedings of the 8th International Symposium on Search-Based Software Engineering.