summaryrefslogtreecommitdiff
blob: 74f1e0ab0abcf89649783a1193ab0e02b5b875f1 (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
68
69
70
71
72
73
74
75
76
77
# Gentoo Linux Bash Shell Command Completion
#
# Copyright 2024 Gentoo Authors
# Distributed under the terms of the GNU General Public License, v2 or later

#
# emaint completion (from sys-apps/portage)
#

_emaint() {
    local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}

    local -A OPTS=(
        [COMMANDS]='all binhost cleanresume merges movebin moveinst sync world'
        [STANDALONE]='-h --help -c --check -f --fix --version'
        [LOGS]='-C --clean -p --pretend'
        [LOGS_ARG]='-t --time'
        [MERGES]='-y --yes'
        [SYNC]='-a --auto -A --allrepos'
        [SYNC_ARG]='-r --repo --sync-submodule'
    )

    local i command
    for (( i=1; i <= COMP_CWORD; i++ )); do
        if [[ ${COMP_WORDS[i]} != -* ]]; then
            if [[ " ${OPTS[COMMANDS]} " =~ " ${COMP_WORDS[i]} " ]]; then
                command=${COMP_WORDS[i]}
                break
            else
                COMPREPLY=( $(compgen -W '${OPTS[COMMANDS]}' -- "${cur}") )
                return
            fi
        fi

        [[ ${i} -lt ${COMP_CWORD} && " ${OPTS[LOGS_ARG]} ${OPTS[SYNC_ARG]} " =~ " ${COMP_WORDS[i]} " ]] && ((i++))
    done

    case ${command} in
        logs)
            if [[ ${prev} = -t || ${prev} = --time ]]; then
                COMPREPLY=()
                return
            fi
            ;;
        sync)
            case ${prev} in
                -r|--repo)
                    COMPREPLY=( $(compgen -W "$(_parsereposconf -l)" -- "${cur}") )
                    return
                    ;;
                --sync-submodule)
                    COMPREPLY=( $(compgen -W 'glsa news profiles' -- "${cur}") )
                    return
                    ;;
            esac
            ;;
    esac

    COMPREPLY=( $(compgen -W '${OPTS[STANDALONE]}' -- "${cur}") )
    case ${command} in
        logs)
            COMPREPLY+=( $(compgen -W '${OPTS[LOGS]} ${OPTS[LOGS_ARG]}' -- "${cur}") )
            ;;
        merges)
            COMPREPLY+=( $(compgen -W '${OPTS[MERGES]}' -- "${cur}") )
            ;;
        sync)
            COMPREPLY+=( $(compgen -W '${OPTS[SYNC]} ${OPTS[SYNC_ARG]}' -- "${cur}") )
            ;;
    esac
    if [[ -z ${command} ]]; then
        COMPREPLY+=( $(compgen -W '${OPTS[COMMANDS]}' -- "${cur}") )
    fi
} &&
complete -F _emaint emaint

# vim: ft=sh:et:ts=4:sw=4:tw=80