July 30, 2014

Search Multiple Directories with cd

Posted on July 30, 2014  •  1 minutes  • 143 words
Table of contents

If you use the command line and frequent a particular directory you can set cd to scan, not just current, but other directories as well.

Modify ~/.bash_profile by appending directories to the CDPATH environment variable.

# define base directory for cd command

Restart your terminal session and now you can cd projectDir. cd will reference any subdirectories in the current directory—as well as $HOME/Repos.

Autotabbing Custom Base Directories

You can install an additonal library; bash-completion to use the [tab] key to autocomplete from the cd command.

brew install bash-completion

Add the following to ~/.bash_profile.

# add bash-completion
if [ -f `brew --prefix`/etc/bash_completion ]; then
  . `brew --prefix`/etc/bash_completion

To install bash-completion on other systems and more resources:

Case Insensitive Completion

Update ~/.inputrc file to include the following line:

set completion-ignore-case on

For hyphens and underscores as well:

set completion-map-case on
comments powered by Disqus
Follow me

I work on web & mobile application development, data integration, and AI.