Newer posts are loading.
You are at the newest post.
Click here to check if anything new just came in.

Bash Completion for git on Mac OS X

Most of our development work happens on Macs, but our server infrastructure runs on Ubuntu Linux, so we are used to the great bash command line argument completion feature.

Bash completion is basically a collection of bash scripts, which know the command line argument options for most popular command line applications. So additionally to the completion of directory- and filenames (by pressing tab), you also get completion of command line arguments.

Now Mac OS X doesn’t ship with bash completion, so to get it running on your Mac, you need to have MacPorts (or another package manager) installed and install the bash-completion package:

sudo port install bash-completion

Now that we have bash completion installed, we still need bash to actually load the scripts. Add the following to your ~/.profile (if the file .profile doesn’t exist in your home directory, just create an empty file):

if [ -f /opt/local/etc/bash_completion ]; then
. /opt/local/etc/bash_completion

You now need close and reopen your Terminal for bash to reload your .profile (you can also run source ~/.profile instead).

Let’s try if it works by entering dd<space> in your Terminal and pressing tab twice. You should see the command line options for the dd utility:

Fast:~ schmidp$ dd<space><tab><tab>
--help --version bs= cbs= conv= count= ibs= if= obs= of= seek= skip=

Yay, we have working bash completion!

But we are not finished yet, as the bash-completion package ships without git support. So let’s run the following commands:

cd /opt/local/etc/bash_completion.d
sudo curl -O

Reload your .profile again (see above), enter git su and press tab. Bash should now autocomplete your command to git submodule.

Tags: Development

Don't be the product, buy the product!