Use `z` to Quickly `cd` to Frequent/Recent Folders

TLDR: z <substring of folder name> instead of cd relative/or/full/path/to/folder.


Typing Long Paths is Tedious

There’s lots of times per day where I have to switch between various folders in the terminal, and they’re often deep inside different trees with very long paths.

For instance, if I’m currently in ~/vhosts/localhost/wordcamp.test/public_html/wp-content/mu-plugins/blocks/source/blocks/schedule, it’s a pain to type cd ../../../../plugins/gutenberg (including manually counting the number of folders to jump back). I could type the full path to avoid that counting, but that would also be very long. Tab completion helps a bit, but not nearly enough.

z Makes it Easy

z makes that it so that I can just type z camp gut, or z camp sched, or any substring or regex that matches the unique path.

It Also Supports Tab Completion

It also supports tab completion to disambiguate between folders with the same name within different trees. Say I have ~/vhosts/localhost/wordcamp.test/public_html/wp-content/plugins/gutenberg and ~/vhosts/localhost/wp-develop.test/public_html/src/wp-content/plugins/gutenberg; if I type z gut, I’ll get this output:

> z gut
gutenberg/ gutenberg/

> z /Users/iandunn/vhosts/localhost/wCode language: Bash (bash)

The second line is a new z command with the path for the 2 matches, up until the point where the paths diverge. If I then type p<tab><enter>, it’ll take me to the gutenberg folder within wp-develop.test, instead of the one inside wordcamp.test. If I type c<tab><enter>, then it’d take me to the one inside wordcamp.test.

One thought on “Use `z` to Quickly `cd` to Frequent/Recent Folders

Leave a Reply

Your email address will not be published. Required fields are marked *