File: rex-tab-completion.bash

package info (click to toggle)
rex 1.16.0-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 3,020 kB
  • sloc: perl: 36,298; xml: 264; sh: 51; makefile: 13
file content (66 lines) | stat: -rw-r--r-- 1,907 bytes parent folder | download | duplicates (4)
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
# bash completion for rex

_rex()
{
    local cur prev

    COMPREPLY=()
    _get_comp_words_by_ref -n : cur prev

    if [[ "$cur" == -* ]]; then
        COMPREPLY=( $(compgen -W '$(_parse_help "$1" -h)' -- "$cur") )
        return
    fi

    case "$prev" in
        -f)
            _filedir
            ;;
        -H)
            if [ -f Rexfile ]; then
                hosts=( $(rex -Ty 2>/dev/null | perl -MYAML -MList::Util=uniq -E 'my $groups = Load(join "", <>)->{groups}; say $_->{name} for uniq sort map { @{ $groups->{$_} } } keys %$groups') )
                COMPREPLY=( $( compgen -W '${hosts[@]}' -- "$cur" ) ) || _known_hosts_real -a "$cur"
            fi
            ;;
        -E)
            if [ -f Rexfile ]; then
                envs=( $(rex -Ty 2>/dev/null | perl -MYAML -e 'my $envs = Load(join "", <>)->{envs}; print "$_\n" for @$envs;') )
                COMPREPLY=( $( compgen -W '${envs[@]}' -- "$cur" ) )
            fi
            ;;
        -G)
            if [ -f Rexfile ]; then
                groups=( $(rex -Ty 2>/dev/null | perl -MYAML -e 'my $groups = Load(join "", <>)->{groups}; print "$_\n" for keys %$groups;') )
                COMPREPLY=( $( compgen -W '${groups[@]}' -- "$cur" ) )
            fi
            ;;

        *)
            if [ -f Rexfile ]; then
                tasks=( $(rex -Ty 2>/dev/null | perl -MYAML -E 'my $tasks = Load(join "", <>)->{tasks}; say $_ for @$tasks;') )
                COMPREPLY=( $( compgen -W '${tasks[@]}' -- "$cur" ) )
            fi
            ;;
    esac

    _rex_fix_colon_reply
    return 0

} &&
complete -F _rex rex

_rex_fix_colon_reply()
{
    local colprefs i
    colprefs=${cur%"${cur##*:}"}
    i=${#COMPREPLY[*]}
    while [ $((--i)) -ge 0 ]; do
        COMPREPLY[$i]=${COMPREPLY[$i]#"$colprefs"}
    done
}

# Local variables:
# mode: shell-script
# indent-tabs-mode: nil
# End:
# ex: ts=4 sw=4 et filetype=sh