I’m a lazy/impatient typist and therefore a big fan of shell completion. There’s a lot of good completion support for common programs, but what if I want to have shell completion for a custom program or shell function? A quick and easy way is to bind one of the pre-defined completion functions, as I learned today.

Eg. I have a shell function “sshr” to log me into a remote host as root:

sshr() { /usr/bin/ssh "root@$@" ;}

To have the shell use the same expansion rules as regular ssh, bind it like this:

complete -F _ssh sshr

To get a list of predefined completion rules, run “complete -p”

This and more from