Skip to content

Add shell auto completion rules for git subcommands

Following #3 (closed), we can generate list of remotes, branches/tags, packages to checkout.

Git standard completion is very powerful and flexible, and the following code is valid bash to extend completion of git lb-checkout:

_git_lb_checkout ()
{       
        local i c=1 b=-1
        while [ $c -lt $cword ]; do
                i="${words[c]}"
                case "$i" in
                -*) ;;
                *) ((b++)) ;;
                esac
                ((c++))
        done

        case "$cur" in
        --*)
                __gitcomp "
                        --commit --no-commit --quiet --verbose --debug
                        "
                ;;
        *)
            case $b in
              0) if [[ "$cur" != */* ]] ; then
                   __gitcompadd "Gaudi LHCb Lbcom" "" "$cur" "/"
                 else
                   __gitcomp "${cur%%/*}/master ${cur%%/*}/v30r2"
                 fi ;;
              1) __gitcomp "GaudiPluginService Tools/Entity" ;;
            esac
        esac
}