A method would be to add the auto completion package using MacPorts or Homebrew. I would advise you to switch to Homebrew anyway if you're still using MacPorts. Just a personal preference though.
Install the bash-completion package
Anyway, install the bash-completion package:
sudo port install bash-completion
brew install bash-completion
This also works with Fink too, I suppose.
You should then edit your ~/.bash_profile and add the following if you used MacPorts:
if [ -f /opt/local/etc/bash_completion ]; then
/opt/local/etc/bash_completion
fi
If you instead used Homebrew, add the following:
if [ -f `brew --prefix`/etc/bash-completion ]; then
. `brew --prefix`/etc/bash-completion
fi
Restart the Terminal or open a new shell. Now sudo should autocomplete for you, and a couple of other things as well.
I'm afraid though that MacPorts by itself won't autocomplete, and Bash just doesn't know which packages exist. Luckily, there's remedy for that.
Install autocompletion for MacPorts
According to the MacPorts Wiki you can enable autocompletion for port <command>. It also completes package names. Furthermore, it should enable autocompletion for all other installed ports.
Add the following line to /opt/local/etc/macports/variants.conf:
+bash_completion
Then restart the Terminal or open a new shell. Thanks to Daniel Beck and Kevin Reid for pointing those things out.
Install autocompletion for Homebrew
You can install Homebrew's own autocompletion script by executing:
ln -s "/usr/local/Library/Contributions/brew_bash_completion.sh" "/usr/local/etc/bash_completion.d"
and then restarting the Terminal. Now Homebrew will autocomplete its own commands and also its packages. Problem solved.