Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to enable autocompletion of my homebrew commands. Homebrew automatically creates the folder bash_completion.d and sym-links all completion files there.

$ ls -a `brew --prefix`/etc/bash_completion.d/
.  ..  git-completion.bash

As you can see I have completions for brew and git. So I try to run the files:

[ -d `brew --prefix`/etc/bash_completion.d ] && source `brew --prefix`/etc/bash_completion.d/*

This is in my ~/.bash_profile, and I'm expecting this to source all the files in bash_completion.d. When I try it out later in the terminal, only the completion for brew works.

Is there something I'm missing?

share|improve this question
up vote 1 down vote accepted

The source help eludes that mystery:

source: source filename [arguments]
    Read and execute commands from FILENAME and return.  The pathnames
    in $PATH are used to find the directory containing FILENAME.  If any
    ARGUMENTS are supplied, they become the positional parameters when
    FILENAME is executed.

which means that when you feed it a list of filenames generated through a glob, only the first is sourced, while all filenames after it are considered its arguments. To source all files in your completion directory, you will need to loop over it, i.e.

for f in "$(brew --prefix)"/etc/bash_completion.d/*; do source "$f"; done

However, as you use homebrew’s bash completion, there is a much better way: simply

source "$(brew --prefix)"/etc/bash_completion

which will take charge of sourcing anything found in the pertinent completion directories, while also adding a plethora of useful completions of its own.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .