Glad You're Ready. Let's Get Started!

Let us know how we can contact you.

Thank you!

We'll respond shortly.

  • Blog Navigation
CDPATH Bash completion in OSX

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
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.

  • Paul J. Lucas

    How do you do the opposite? That is _disable_ CDPATH completion on systems that have it? I want CDPATH to be used only when I actually am cd’ing.

Share This