CDPATH Bash completion in OSX

October 14, 2013 Andrew Bruce

Setting the CDPATH environment variable saves you having to cd to commonly-used parent directories. I usually put my main workspace directory in there to allow direct directory changes to project dirs, as well as ‘..’ to allow jumping to sibling directories.

Having recently switched from Ubuntu (again), where console niceties are the default, I was frustrated to find that bash didn’t complete my CDPATH entries. However, it’s easily fixed with Homebrew:

brew install bash-completion

This works: new bash shells will complete CDPATH. However, it slows shell load time down considerably. This problem is fixed in the latest bash-completion script, but it’s only compatible with Bash 4. OSX ships with version 3. Let’s upgrade it:

brew unlink bash-completion
brew install bash
sudo -i
echo "/usr/local/bin/bash" >> /etc/shells
exit
brew install bash-completion
chsh -s /usr/local/bin/bash

Now new shells will have CDPATH completion, and will start up in a reasonable time. Plus, you have the latest Bash. If you need to back this out, check out the comments on the accepted answer to a question that helped me arrive at this solution.

About the Author

Biography

More Content by Andrew Bruce
Previous
Pivotal's Plans for Strata Conference + Hadoop World, Oct 28-29 in NYC
Pivotal's Plans for Strata Conference + Hadoop World, Oct 28-29 in NYC

Since the Strata Conference + Hadoop World combined forces, it has become not only the largest Hadoop comm...

Next
Pixel Perfect – When Designers Develop and Developers Design
Pixel Perfect – When Designers Develop and Developers Design

With over a million apps in Google Play, and slightly less than that in the iTunes App Store, design has be...

Enter curious. Exit smarter.

Register Now