_known_host()
{
local cur prev hosts
COMPREPLY=()
cmd="${COMP_WORDS[0]}"
cur="${COMP_WORDS[COMP_CWORD]}"
if [[ "C$cmd" == "Cssh" ]]; then
#補全的列表來自文件~/.known_hosts
COMPREPLY=( $(compgen -W "`cat ~/.known_hosts`" -- ${cur}) )
return 0
fi
}
#指定上述函數用於補全ssh命令的參數
complete -F _known_host ssh
參考
http://www.debian-administration.org/article/316/An_introduction_to_bash_completion_part_1