Q:

How can I create something similar to an alias, that does properly expand to the initial command?

I have set up aliases for apt-get update, apt-get install, and so on. 
Thats quite convenient. But what I really would like to have is something like this: 
type agi TAB vi and have it automatically list all packages starting with vi, as it would happen when issuing apt-get install TAB vi.  
Would something like this be achievable somehow, maybe by writing a little script?

A:

Bash programmable completion is something I haven't bothered much with myself, but I believe this will do what you want (NB assumes bash version 4.0 or newer. If you run Ubuntu 10.04 or newer, you're good.):
alias agi='apt-get install'
_agi_completion() { 
    mapfile -t COMPREPLY < <(apt-cache --no-generate pkgnames "${COMP_WORDS[COMP_CWORD]}")
}
complete -F _agi_completion agi

Programmable Completion in bash's manual explains how it works, though it's quite complex.

