aboutsummaryrefslogtreecommitdiffstats
path: root/bash_completion/kerl
blob: 62efa0051c9187270977f0e7ef5daea2ca0f2209 (plain) (blame)
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
# bash_completion for kerl

_kerl()
{
    local cur prev
    _get_comp_words_by_ref cur prev

    case $prev in
        kerl)
            COMPREPLY=( $( compgen -W "build install update list delete active status" -- "$cur" ) )
            ;;
        list)
            COMPREPLY=( $( compgen -W "releases builds installations" -- "$cur" ) )
            ;;
        build)
            if [ "$COMP_CWORD" -eq 2 ]; then
                if [ -f "$HOME/.kerl/otp_releases" ]; then
                    RELEASES=`cat "$HOME/.kerl/otp_releases"`
                fi
                COMPREPLY=( $( compgen -W "git $RELEASES" -- "$cur") )
            else
                if [ -f "$HOME/.kerl/otp_builds" ]; then
                    BUILDS=`cat "$HOME/.kerl/otp_builds" | cut -d "," -f 2`
                fi
                COMPREPLY=( $( compgen -W "$BUILDS" -- "$cur") )
            fi
            ;;
        installation)
            if [ -f "$HOME/.kerl/otp_installations" ]; then
                PATHS=`cat "$HOME/.kerl/otp_installations" | cut -d " " -f 2`
            fi
            COMPREPLY=( $( compgen -W "$PATHS" -- "$cur") )
            ;;
        install)
            if [ -f "$HOME/.kerl/otp_builds" ]; then
                BUILDS=`cat "$HOME/.kerl/otp_builds" | cut -d "," -f 2`
            fi
            COMPREPLY=( $( compgen -W "$BUILDS" -- "$cur") )
            ;;
         deploy)
            if [ "$COMP_CWORD" -eq 3 ]; then
                if [ -f "$HOME/.kerl/otp_installations" ]; then
                    PATHS=`cat "$HOME/.kerl/otp_installations" | cut -d " " -f 2`
                fi
            fi
            COMPREPLY=( $( compgen -W "$PATHS" -- "$cur") )
            ;;
        delete)
            COMPREPLY=( $( compgen -W "build installation $words" -- "$cur") )
            ;;
        update)
            COMPREPLY=( $( compgen -W "releases agner" -- "$cur") )
            ;;
        agner)
            if [ "$COMP_CWORD" -eq 3 ]; then
                if [ -f "$HOME/.kerl/otp_builds" ]; then
                    BUILDS=`cat "$HOME/.kerl/otp_builds" | cut -d "," -f 2`
                fi
            fi
            COMPREPLY=( $( compgen -W "$BUILDS" -- "$cur") )
            ;;
        *)
            if [ "$COMP_CWORD" -eq 3 ]; then
                if [ -f "$HOME/.kerl/otp_builds" ]; then
                    BUILDS=`cat "$HOME/.kerl/otp_builds" | cut -d "," -f 2`
                fi
                if [ -n "$BUILDS" ]; then
                    for b in $BUILDS; do
                        if [ "$prev" = "$b" ]; then
                            _filedir
                            return 0
                        fi
                    done
                fi
            fi
            ;;
    esac
}
complete -F _kerl kerl