This is in my .bashrc:

alias p='sudo apt-get'; complete -F _apt_get p

I've found the autocompletion only works if I've used autocompletion for apt-get at least once before trying to use it with the p alias.

Why is that?

1 Answer 1


That's because completions are loaded dynamically by the "bash-completions" library. This works because the completion specifications are kept "in a file corresponding to the name of the command" (man bash).

Add this to your .bashrc:

_completion_loader apt-get

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .