This will allow you to include additional directories to what cd
will look at for completions. From the bash
man page:
The search path for the cd command. This is a colon-separated list of directories in which the shell looks for destination directories specified by the cd command.
Here is an example of how you would benefit:
You set CDPATH the same way you do your PATH variable, with a colon separated list. Here is an example:
CDPATH=.
CDPATH=$CDPATH:/var/www
CDPATH=$CDPATH:$HOME/Projects
export CDPATH
The completions weren't working for me until I found this article, CDPATH Bash completion in OSX.
The article says you need to install bash_completion.
brew install bash-completion
This didn't fix it for me. I did a brew link bash-completion
and brew said it was already linked. I found another article that said to source bash_completion in my .bash_profile:
. $(brew --prefix bash-completion)/etc/bash_completion
The article also says that you should update to the latest bash to fix a slowness/compatibility issue.
...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.
You can check your version of bash to make sure that this step is necessary:
bash -version
If you are running version 3 and need to upgrade:
brew install bash
I don't know if this step is necessary, but I ran this command to switch my user's bash to the new instance of bash:
chsh -s /usr/local/bin/bash