aboutsummaryrefslogtreecommitdiff
path: root/bash-completion/adjutrix
blob: 118046056083bb6a5b65b3410a0dbe966981e49a (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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# Bash completion function for adjutrix
# Written by Mike Kelly
# vim: set et sw=4 sts=4 ts=4 ft=sh :

# NOTE: This is still a work in progress, don't expect it to work well or
# properly right now.

_adjutrix_get_repodir() {
    local repodir
    [[ -f ./profiles/repo_name ]] && repodir=$(readlink -f $(pwd))
    [[ -z "${repodir}" && -f ../profiles/repo_name ]] \
        && repodir=$(readlink -f $(pwd)/..)
    [[ -z "${repodir}" && -f ../../profiles/repo_name ]] \
        && repodir=$(readlink -f $(pwd)/../..)
    [[ -z "${repodir}" ]] && return 1
    echo "${repodir}"
}

_adjutrix() {
    local cur prev opts repodir
    COMPREPLY=()
    cur=${COMP_WORDS[COMP_CWORD]}
    prev=${COMP_WORDS[COMP_CWORD-1]}

    # Figure out what our repository dir is
    for i in $(seq 0 ${COMP_CWORD}) ; do
        if [[ ${COMP_WORDS[i]} == "-D" \
            || ${COMP_WORDS[i]} == "--repository-dir" ]]
        then
            repodir=${COMP_WORDS[i+1]}
        fi
    done
    [[ -z "${repodir}" ]] && repodir="$(_adjutrix_get_repodir)"

    opts="--find-stable-candidates -s \
        --find-dropped-keywords -d \
        --find-insecure-packages -i \
        --find-unused-packages -U \
        --keyword-graph -k \
        --reverse-deps -r \
        --what-needs-keywording -w \
        --display-profiles-use -u \
        --display-default-system-resolution -S \
        --build-downgrade-check-list \
        --downgrade-check \
        --version -V \
        --help -h \
        --log-level \
        --no-colour \
        --no-color \
        --repository-dir -D \
        --category -C \
        --package -P \
        --profile \
        --unstable \
        --write-cache-dir"

    case "${cur}" in
        -*)
            COMPREPLY=($(compgen -W "${opts}" -- "${cur}"))
            return 0
            ;;
        *)
            case "${prev}" in
                ## Enum operators
                --log-level)
                    COMPREPLY=($(compgen -W "debug qa warning silent" -- "${cur}"))
                    return 0
                    ;;

                --category|-C)
                    [[ -z "${repodir}" ]] && return 0
                    COMPREPLY=($(compgen -W "$(< ${repodir}/profiles/categories)" -- "${cur}"))
                    return 0
                    ;;
                --package|-P)
                    [[ -z "${repodir}" ]] && return 0
                    # borrowed from the gentoo bashcomp script
                    local p
                    COMPREPLY=($(compgen -W "$(\
                        builtin cd ${repodir}; \
                        for p in *-*/${cur}*; do \
                            [[ -d ${p} ]] && \
                            echo ${p##*/} ; \
                        done)" -- "${cur}"))
                    return 0
                    ;;

                --find-stable-candidates|-s|--find-dropped-keywords|-d)
                    [[ -z "${repodir}" ]] && return 0
                    COMPREPLY=($(compgen -W "$(< ${repodir}/profiles/arch.list)" -- "${cur}"))
                    return 0
                    ;;
                --what-needs-keywording|-w)
                    # still needs some improvement to do package names as the second arg...
                    COMPREPLY=($(compgen -W "$(< ${repodir}/profiles/arch.list)" -- "${cur}"))
                    return 0
                    ;;

                --repository-dir|-D|--write-cache-dir)
                    _filedir -d
                    return 0
                    ;;

                --profile)
                    COMPREPLY=($(compgen -W "$(sed -n 's,^[^#][^[:space:]]*[[:space:]]*\([^[:space:]]*\).*,\1,p' "${repodir}/profiles/profiles.desc")" -- "${cur}"))
                    return 0
                    ;;

                *)
                    ;;
            esac
            ;;
    esac
}
complete -o filenames -F _adjutrix adjutrix