cd'ing to frequently-used directories in ZSH

Gabe Berke-Williams

Josh just dropped some sweet, sweet ZSH knowledge. I spend a lot of time in the directories under $HOME/thoughtbot/ and $HOME/src, and to get there I type (for example) cd ~/thoughtbot/hoptoad. There is a better way!

First, add this to your ~/.zshrc and source it:

setopt auto_cd
cdpath=($HOME/thoughtbot $HOME/src)

Obviously, use different paths in cdpath depending on which directories you cd into a lot.

Now let’s try it out:

$ cd rspec-core # Autocompleted from rspe<TAB>
$ pwd
/Users/gabe/src/rspec-core
$ cd hoptoad
$ pwd
/Users/gabe/thoughtbot/hoptoad

Seriously, check out your coworkers’ dotfiles. It can improve your workflow efficiency by an order of magnitude. Like most of the thoughtbot crew, Josh keeps his dotfiles on Github.

We've been helping engineering teams deliver exceptional products for over 20 years. Our designers, developers, and product managers work closely with teams to solve your toughest software challenges through collaborative design and development. Learn more about us.