A basic description is here, a guide to writing your own extensions is here and another (Debian-based) guide is here. And here's a fuller featured introduction to the
complete command (the command that facilitates this behaviour).
This functionality in bash is provided by bash-completion and similar functionality is included in zsh.@ http://stackoverflow.com/questions/3690655/auto-complete-command-line-arguments