aboutsummaryrefslogtreecommitdiff
path: root/bash-completion/cave
blob: 80dc2b747528b4f65ed64953e11b8f7a4a5982c0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# Bash completion function for cave
# Written by Mike Kelly
# vim: set et sw=4 sts=4 ts=4 ft=sh :

# Based in part upon 'git' bash completion from git-1.6.4.2

__cave_find_cmd() {
    local w c=1 cmd

    while [[ $c -lt $COMP_CWORD ]] ; do
        w="${COMP_WORDS[c]}"
        case "${w}" in
            --*) ;;
            --help) cmd="help"; break ;;
            *) cmd="${w}"; break ;;
        esac
    done

    echo "${cmd}"
}

__cave_global() {
    case "${prev}" in
        --log-level)
            COMPREPLY=( $(compgen -W "debug qa warning slient" -- "${cur}") )
            ;;
        --environment|-E)
            COMPREPLY=( $(compgen -W "paludis: portage:" -- "${cur}") )
            ;;
        *)
            case "${cur}" in
                -*)
                    COMPREPLY=( $(compgen -W "-E --environment --log-level" -- "${cur}") )
                    ;;
                *)
                    COMPREPLY=( $(compgen -W "$(cave print-commands -a)" -- "${cur}") )
                    ;;
            esac
    esac
}

__cave_help() {
    # only complete once
    if [[ "${prev}" == "help" ]] ; then
        COMPREPLY=( $(compgen -W "$(cave print-commands -a) -a --all" -- "${cur}") )
    fi
}

__cave_sync() {
    COMPREPLY=( $(compgen -W "$(cave print-repositories) --sequential" -- "${cur}") )
}

_cave() {
    local cmd=`_cave_find_cmd` prev=`_get_pword` cur=`_get_cword`

    COMPREPLY=()

    if [[ -z "${cmd}" ]] ; then
        __cave_global
    else
        if [[ "$(type -t "__cave_${cmd}")" == "function" ]] ; then
            "__cave_${cmd}"
        fi
    fi
}
complete -F _cave cave