summaryrefslogtreecommitdiff
blob: b1ef0f18245cc8970d2edca3e5bf5ef083602b3a (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
# Gentoo Linux Bash Shell Command Completion
#
# Copyright 1999-2013 Gentoo Authors
# Distributed under the terms of the GNU General Public License, v2 or later

_glsa_check() {
    COMPREPLY=()
    local cur="${COMP_WORDS[COMP_CWORD]}"
    local opts="-l --list -d --dump --print -t --test -p --pretend -f --fix -i
    --inject -n --nocolor -e --emergelike -h --help -V --version -v --verbose
    -c --cve -m --mail -q --quiet -r --reverse"

    if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]] ; then
        COMPREPLY=($(compgen -W "${opts}" -- "${cur}"))
        return 0
    fi

    # too slow otherwise
    local cache_file=${ROOT}/tmp/.completion.glsa-check.cache
    if [[ ! -f ${cache_file} ]] || \
        (( $(date +%s) - $(stat -c %Y "${cache_file}") > 4 * 3600 ))
    then
        glsa-check -nl 2>/dev/null | \
            sed -n -e  's/^\([[:digit:]]\+-[[:digit:]]\+\) .*$/\1/p' > \
                "${cache_file}"
    fi

    COMPREPLY=($(compgen -W "${opts} all new affected $(< "${cache_file}")" -- "${cur}"))
} &&
complete -F _glsa_check glsa-check

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