8

I wanted to have bash autocompletion for git commands, so I dropped a bash script file into /opt/local/etc/bash_completion.d/.

When I open a new Terminal, the script file in /opt/local/etc/bash_completion.d/ does not get executed. I have verified that the script file is working by running:

source /opt/local/etc/bash_completion.d/git-completion.bash

Are there any steps missing here to ask OS X to automatically execute scripts in /opt/local/etc/bash_completion.d/?

8

In order to automatically load all scripts from a directory, put this in your ~/.bashrc file

# LOAD ALL AUTOCOMPLETIONS IF ANY ARE INSTALLED
if [ -d /usr/local/etc/bash_completion.d ]; then
    for F in "/usr/local/etc/bash_completion.d/"*; do
        if [ -f "${F}" ]; then
            source "${F}";
        fi
    done
fi
3

Yes you need to load them into your shell.

This is done by editing ~/.bashrc or ~/.bash_profile and adding the command . filename for each file. This loads the file and makes the functions available. i.e. put your source command in one of these files.

Note that you should not be adding to /opt/local/etc/bash_completion.d/ as only macports should write there. Put the files in your home directory e.g. ~/.bash_completion.d/git-completion.bash

You must log in to answer this question.

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