bash-completion is the package responsible for autocompletion in the Ubuntu cli (by default), whenever you write:
$ sudo apt-get [TAB][TAB] #or any other cli app
A script on /usr/share/bash-completion/ is executed which list the options you have.
$ sudo apt-get autoclean build-dep check dist-upgrade dselect-upgrade purge source upgrade autoremove changelog clean download install remove update
This is plain awesome, however it has the drawback that it requires to read many of these same files at the beginning of your shell session (every time you open a new terminal, gnome-terminal) which may take time (2 seconds on my current machine, core duo, 4gb of ram). A new version of bash-completion has been on the air for some time, the 2.0 version loads a lot faster (3x on my own machine).
On ubuntu bash-completion >= 2.0 is provided in the following releases:
bash-completion | 1:2.0-1ubuntu2 | quantal | source, all bash-completion | 1:2.0-1ubuntu3 | raring | source, all bash-completion | 1:2.0-1ubuntu3 | saucy | source, all
So if you’re running Quantal|Raring|Saucy you’re covered, if you’re not (for example if you’re running the Ubuntu Precise release) you can do it easily.
1.- Download the bash-completion package
2.- Install it
$ sudo dpkg -i bash-completion*.deb
The package has no dependencies, so it’s a drop and replace action. Thanks to the bash-completion team for the great optimization work =D!