Skip to content

Instantly share code, notes, and snippets.

@zjhiphop

zjhiphop/CDPATH.md

Forked from flackend/CDPATH.md
Created Nov 6, 2018
Embed
What would you like to do?
Instructions for setting up CDPATH completions on Mac.

CDPATH

Overview

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.

Usage

Here is an example of how you would benefit:

usage example

Setting CDPATH

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

Bash Completion

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

Sourcing 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

Get Latest Bash

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.