The bash completion project provides a lot of interesting functionalities to the bash shell, one of the most used completion tips is when the user hits the tab key to complete the name of a file. Another interesting tip is applied to the cd command, when you type a cd (change directory) and after you hit the tab key you should see only the directories instead of all the files. this can be done using the complete command.

 

For programmers like me,  it is very useful the completion of the make command, if I type the tab key after make I want to see all the rules I can call. The bash-completion gives this functionality to me.

To use the bash-completion you have to use the MacPorts

macports

Open a terminal window and issue the following commands:

$ sudo port install bash-completion

Password:

Warning: port definitions are more than two weeks old, consider using selfupdate

--->  Computing dependencies for bash-completion

--->  Dependencies to be installed: bash

--->  Fetching archive for bash

--->  Attempting to fetch bash-4.2.37_0.darwin_12.x86_64.tbz2 from http://mse.uk.packages.macports.org/sites/packages.macports.org/bash

--->  Attempting to fetch bash-4.2.37_0.darwin_12.x86_64.tbz2 from http://lil.fr.packages.macports.org/bash

--->  Attempting to fetch bash-4.2.37_0.darwin_12.x86_64.tbz2 from http://packages.macports.org/bash

--->  Fetching distfiles for bash

--->  Attempting to fetch bash42-001 from http://fco.it.distfiles.macports.org/mirrors/macports-distfiles/bash

--->  Attempting to fetch bash42-002 from http://fco.it.distfiles.macports.org/mirrors/macports-distfiles/bash

--->  Attempting to fetch bash42-003 from http://fco.it.distfiles.macports.org/mirrors/macports-distfiles/bash

--->  Attempting to fetch bash42-004 from http://fco.it.distfiles.macports.org/mirrors/macports-distfiles/bash

--->  Attempting to fetch bash42-005 from http://fco.it.distfiles.macports.org/mirrors/macports-distfiles/bash

--->  Attempting to fetch bash42-006 from http://fco.it.distfiles.macports.org/mirrors/macports-distfiles/bash

--->  Attempting to fetch bash42-007 from http://fco.it.distfiles.macports.org/mirrors/macports-distfiles/bash

--->  Attempting to fetch bash42-008 from http://fco.it.distfiles.macports.org/mirrors/macports-distfiles/bash

--->  Attempting to fetch bash42-009 from http://fco.it.distfiles.macports.org/mirrors/macports-distfiles/bash

--->  Attempting to fetch bash42-010 from http://fco.it.distfiles.macports.org/mirrors/macports-distfiles/bash

--->  Attempting to fetch bash42-011 from http://fco.it.distfiles.macports.org/mirrors/macports-distfiles/bash

--->  Attempting to fetch bash42-012 from http://fco.it.distfiles.macports.org/mirrors/macports-distfiles/bash

--->  Attempting to fetch bash42-013 from http://fco.it.distfiles.macports.org/mirrors/macports-distfiles/bash

--->  Attempting to fetch bash42-014 from http://fco.it.distfiles.macports.org/mirrors/macports-distfiles/bash

--->  Attempting to fetch bash42-015 from http://fco.it.distfiles.macports.org/mirrors/macports-distfiles/bash

--->  Attempting to fetch bash42-016 from http://fco.it.distfiles.macports.org/mirrors/macports-distfiles/bash

--->  Attempting to fetch bash42-017 from http://fco.it.distfiles.macports.org/mirrors/macports-distfiles/bash

--->  Attempting to fetch bash42-018 from http://fco.it.distfiles.macports.org/mirrors/macports-distfiles/bash

--->  Attempting to fetch bash42-019 from http://fco.it.distfiles.macports.org/mirrors/macports-distfiles/bash

--->  Attempting to fetch bash42-020 from http://fco.it.distfiles.macports.org/mirrors/macports-distfiles/bash

--->  Attempting to fetch bash42-021 from http://fco.it.distfiles.macports.org/mirrors/macports-distfiles/bash

--->  Attempting to fetch bash42-022 from http://fco.it.distfiles.macports.org/mirrors/macports-distfiles/bash

--->  Attempting to fetch bash42-023 from http://fco.it.distfiles.macports.org/mirrors/macports-distfiles/bash

--->  Attempting to fetch bash42-024 from http://fco.it.distfiles.macports.org/mirrors/macports-distfiles/bash

--->  Attempting to fetch bash42-025 from http://fco.it.distfiles.macports.org/mirrors/macports-distfiles/bash

--->  Attempting to fetch bash42-026 from http://fco.it.distfiles.macports.org/mirrors/macports-distfiles/bash

--->  Attempting to fetch bash42-027 from http://fco.it.distfiles.macports.org/mirrors/macports-distfiles/bash

--->  Attempting to fetch bash42-028 from http://fco.it.distfiles.macports.org/mirrors/macports-distfiles/bash

--->  Attempting to fetch bash42-029 from http://fco.it.distfiles.macports.org/mirrors/macports-distfiles/bash

--->  Attempting to fetch bash42-030 from http://fco.it.distfiles.macports.org/mirrors/macports-distfiles/bash

--->  Attempting to fetch bash42-031 from http://fco.it.distfiles.macports.org/mirrors/macports-distfiles/bash

--->  Attempting to fetch bash42-032 from http://fco.it.distfiles.macports.org/mirrors/macports-distfiles/bash

--->  Attempting to fetch bash42-033 from http://fco.it.distfiles.macports.org/mirrors/macports-distfiles/bash

--->  Attempting to fetch bash42-034 from http://fco.it.distfiles.macports.org/mirrors/macports-distfiles/bash

--->  Attempting to fetch bash42-035 from http://fco.it.distfiles.macports.org/mirrors/macports-distfiles/bash

--->  Attempting to fetch bash42-036 from http://fco.it.distfiles.macports.org/mirrors/macports-distfiles/bash

--->  Attempting to fetch bash42-037 from http://fco.it.distfiles.macports.org/mirrors/macports-distfiles/bash

--->  Attempting to fetch bash-4.2.tar.gz from http://fco.it.distfiles.macports.org/mirrors/macports-distfiles/bash

--->  Verifying checksum(s) for bash

--->  Extracting bash

--->  Applying patches to bash

--->  Configuring bash

--->  Building bash

--->  Staging bash into destroot

--->  Installing bash @4.2.37_0

--->  Activating bash @4.2.37_0

--->  Cleaning bash

--->  Fetching archive for bash-completion

--->  Attempting to fetch bash-completion-2.0_1.darwin_12.noarch.tbz2 from http://mse.uk.packages.macports.org/sites/packages.macports.org/bash-completion

--->  Attempting to fetch bash-completion-2.0_1.darwin_12.noarch.tbz2.rmd160 from http://mse.uk.packages.macports.org/sites/packages.macports.org/bash-completion

--->  Installing bash-completion @2.0_1

--->  Activating bash-completion @2.0_1

 

To use bash_completion, add the following lines at the end of your .bash_profile:

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

      . /opt/local/etc/profile.d/bash_completion.sh

  fi

The port bash-completion >=2.0 requires bash >=4.1; please make sure

you are using /opt/local/bin/bash by changing the preferences of your

terminal accordingly. If your version of bash is too old, the script

above will not modify your shell environment and no extended completion

will be available.

--->  Cleaning bash-completion

--->  Updating database of binaries: 100.0%

--->  Scanning binaries for linking errors: 100.0%

--->  No broken files found.


 

To use bash_completion, add the following lines at the end of your .bash_profile:

$ cd

$ echo " if [ -f /opt/local/etc/profile.d/bash_completion.sh ]; then" >> .bash_profile

$ echo ". /opt/local/etc/profile.d/bash_completion.sh" >> .bash_profile

$ echo  "fi" >> .bash_profile


 

Last, you need to change the command Terminal.app uses to launch the shell in the preferences.

  1. Goto Menu->Preferences>Startup, and then "Shells open with:"
  2. Select "Command" and enter /opt/local/bin/bash -l to switch to bash provided by MacPorts.
  3. Menu > Preferences > Settings > Shell (per shell type), "Prompt before closing:"
  4. Click "+" and add "bash" to the list of processes.
  5. Quit the terminal app and start it again.


Gg1