Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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/
.  ..  brew_bash_completion.sh  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
add comment

1 Answer

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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.