summaryrefslogtreecommitdiffstats
path: root/completions/_mock
blob: df778a890c9fcec4516e5047fa84795302ba8907 (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
# bash completion for mock                                 -*- shell-script -*-

# Use of this file is deprecated.  Upstream completion is available in
# mock > 1.1.0, use that instead.

_comp_cmd_mock()
{
    local cur prev words cword was_split comp_args
    _comp_initialize -s -- "$@" || return

    local plugins='tmpfs root_cache yum_cache bind_mount ccache'
    local cfgdir=/etc/mock count=0 i

    for i in "${words[@]}"; do
        ((count == cword)) && break
        if [[ $i == --configdir ]]; then
            cfgdir="${words[count + 1]}"
        elif [[ $i == --configdir=* ]]; then
            cfgdir=${i/*=/}
        fi
        ((count++))
    done

    case $prev in
        -h | --help | --copyin | --copyout | --arch | -D | --define | --with | --without | \
            --uniqueext | --rpmbuild_timeout | --sources | --cwd)
            return
            ;;
        -r | --root)
            _comp_compgen_split -- "$(command ls "$cfgdir")" &&
                COMPREPLY=("${COMPREPLY[@]/%.cfg/}")
            return
            ;;
        --configdir | --resultdir)
            _comp_compgen_filedir -d
            return
            ;;
        --spec)
            _comp_compgen_filedir spec
            return
            ;;
        --target)
            # Case-insensitive BRE to match "compatible archs"
            local regex_header='[cC][oO][mM][pP][aA][tT][iI][bB][lL][eE][[:space:]]\{1,\}[aA][rR][cC][hH][sS]'

            # Yep, compatible archs, not compatible build archs
            # (e.g. ix86 chroot builds in x86_64 mock host)
            # This would actually depend on what the target root
            # can be used to build for...
            _comp_compgen_split -- "$(command rpm --showrc | command sed -ne \
                "s/^[[:space:]]*${regex_header}[[:space:]]*:[[:space:]]*\(.*\)/\1/p")"
            return
            ;;
        --enable-plugin | --disable-plugin)
            _comp_compgen -- -W "$plugins"
            return
            ;;
    esac

    [[ $was_split ]] && return

    if [[ $cur == -* ]]; then
        _comp_compgen_help
        [[ ${COMPREPLY-} == *= ]] && compopt -o nospace
    else
        _comp_compgen_filedir '@(?(no)src.r|s)pm'
    fi
} &&
    complete -F _comp_cmd_mock mock

# ex: filetype=sh