Bash Completion on OS X

Hi!

This is a issue fix quite often.. and its really annoying to get it right.
So… I am giving it a try to solve it once and for all, at least for myself.

Whenever I install a Mac for myself, I always use MacPorts (http://www.macports.com) for futher software (such as apache, ant, php ect). So I also use it for bash completion. The thing though is that the bash completion from MacPorts comes without any completions, or so it seems. So how do we get them working? Well… lets take it from the top.

First off…

… I’ll expect you to have MacPort installed and ready to be used. So, lets first configure it to always download the port that includes the completion. This is a page I use to refer to when it comes to configuring macports for bash completion: https://trac.macports.org/wiki/howto/bash-completion. But, for sake of the tutorial, I’ll “copy” the most important information on this page.

Step 1: Install bash-completion

Step 2: Enable bash-completion in your .bash_profile

You have to add bash-completion to your .profile

First, locate the file you are using. If there is a .bash_profile edit this file, if there is only .profile you want to edit this. If neither file exists create .bash_profile.

Open the file in any editor and add the following lines. Make sure you add this after any PATH manipulation as otherwise the bash-completion will not work correctly.

Important: Reopen your Terminal afterwards.

Step 3: Install +bash_completion variant automatically with all ports

Open the file /opt/local/etc/macports/variants.conf in any editor and add a new line:

From now on, MacPorts will automatically select the bash_completion variant for all ports if available.

[Source: https://trac.macports.org/wiki/howto/bash-completion]

So, now we have installed Bash Completion and configured it to download theĀ  bash completion port autimatically if there are any available. The source page also gives some information on how to setup your Terminal.app or iTerm2 in order for it to work. I didn’t copy it since for me its “Bash completion” Hence, it should be in Bash and hence you added it to your .profile.

And then …

Now that we have bash completion installed, and set into our profile file… it is loaded when a new teminal session is created (or the profile file is loaded again using source ~/.profle). Now some curcial comletions are still missing, such as GIT and Mecurial (HG). I found this link for GIT: http://denis.tumblr.com/post/71390665/adding-bash-completion-for-git-on-mac-os-x-snow-leopard but I have not found one for HG yet.

 

I hope this helps some of you, it sure helps me.

Cheers,
Paul

Posted in Apple, Development, Mac, OSX Tagged with: , , , ,
One comment on “Bash Completion on OS X
  1. Ray says:

    it help good.. thank much you
    make happey me

Leave a Reply

Your email address will not be published. Required fields are marked *

*

 

Categories