Step 3: Use bash from MacPorts in your terminal

The port bash-completion at version 2.0 requires at least bash at version 4.1; the older bash 3.2 provided by Apple with Mac OS X is not compatible anymore with this version. 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.

Terminal.app

You need to change the command Terminal.app uses to launch the shell in the preferences.

Menu > Preferences > Startup, "Shells open with:"

Select "Command" and enter /opt/local/bin/bash -l to switch to bash provided by MacPorts.

Click "+" and add "bash" to the list of processes (in newer versions of OS X use "-bash").

Close and reopen any terminal windows

iTerm2

You need to change the command iTerm2 uses to launch the shell in the appropriate profile in the preferences.

Menu > Preferences > Profiles tab

Select your profile, on the right switch to the General tab, see "Command"

Select "Command:" and enter /opt/local/bin/bash -l

Close and reopen any terminal windows

Add /opt/local/bin/bash to the file /etc/shells, otherwise it will be impossible to use AppleScript to tell Terminal to execute scripts (like 'osascript -e "tell application \"Terminal\" to do script \"echo hello\""').

Optional Parts

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:

+bash_completion

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

Additional Modifications

For some tools you need additional configuration as they rely on the login shell instead of using what the Terminal started. You can export SHELL=/opt/local/bin/bash to the environment, which is respected by both tmux and screen. Alternative configuration is shown below.

screen

For screen, you need to set shell /opt/local/bin/bash in your .screenrc.

tmux

For tmux, you need to set set -g default-shell "/opt/local/bin/bash" in your .tmux.conf.