Linux为自己写的程序设定tab自动补全

自己写了一个工具,有很多功能通过参数来区分,例如:工具为vs 命令参数可以为checkout add remove display
想实现在命令行输入vs后按tab键就可以自动补全checkout等命令。需要在~/.bashrc文件下添加如下代码后,执行source .bashrc。在命令行输入vs后按tab就可以实现自动补全了

#Add my own tab automatic completion
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
#############################################

参考:[Tips] DIY制表符键自动补全(bash)

你可能感兴趣的:(Linux)