linux shell 函数,实现自动补全

发布时间 2023-11-06 13:51:48作者: 学不会xuebuhui

实例1:

function _bigtool() {
    COMPREPLY=()
    local cur=${COMP_WORDS[COMP_CWORD]};
    local com=${COMP_WORDS[COMP_CWORD-1]};
    case $com in
    'vs')
        COMPREPLY=($(compgen -W 'checkout display remove add' -- $cur))
        ;;
    *)
        ;;
    esac
    return 0
}
complete -F _bigtool vs

实例2:

_foo()
{
    local cur=${COMP_WORDS[COMP_CWORD]}
    COMPREPLY=( $(compgen -W "exec help test" -- $cur) )
}
complete -F _foo foo