bash自动补全定制

_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

http://www.debian-administration.org/article/An_introduction_to_bash_completion_part_2

你可能感兴趣的:(bash自动补全定制)