There is a great thread about this on the Ubuntu forumsa great thread about this on the Ubuntu forums. Ole J proposes the following alias completion definition function:
function make-completion-wrapper () {
local function_name="$2"
local arg_count=$(($#-3))
local comp_function_name="$1"
shift 2
local function="
function $function_name {
((COMP_CWORD+=$arg_count))
# Quotes here are important
COMP_WORDS=( "$@" \"\${COMP_WORDS[@]:1}\" )
"$comp_function_name"
return 0
}"
eval "$function"
echo $function_name
echo "$function"
}
Use it to define a completion function for your alias, then specify that function as a completer for the alias:
make-completion-wrapper _apt_get _apt_get_install apt-get install
complete -F _apt_get_install apt-inst
I prefer to use aliases for adding always-used arguments to existing programs. For instance, with grep, I always want to skip devices and binary files, so I make an alias for grep. For adding new commands such as grepbin, I use a shell script in my ~/bin folder. If that folder is in your path, it will get autocompleted.