aboutsummaryrefslogblamecommitdiffstats
path: root/bash_completion/kerl
blob: 689463df0b41c2ca78a5521ee2ea032e7e57b1a5 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
           




                          




                                                     









                                                                                                    

                                                              

                                                                      
                

                                                                      




                                                                

                                                                        



                                                           

                                                                  


                                                            

                                            

                                                                            



                                                           



                                                                              
                                                             


                                            

                                                                      













                                                   
#!/bin/bash
# bash_completion for kerl

_kerl()
{
    local cur prev
    if type _get_comp_words_by_ref &>/dev/null ; then
        _get_comp_words_by_ref cur prev
    else
        cur=$2 prev=$3
    fi

    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=$(cut -d ',' -f 2 "$HOME"/.kerl/otp_builds)
                fi
                COMPREPLY=( $( compgen -W "$BUILDS" -- "$cur") )
            fi
            ;;
        installation)
            if [ -f "$HOME"/.kerl/otp_installations ]; then
                PATHS=$(cut -d ' ' -f 2 "$HOME"/.kerl/otp_installations)
            fi
            COMPREPLY=( $( compgen -W "$PATHS" -- "$cur") )
            ;;
        install)
            if [ -f "$HOME"/.kerl/otp_builds ]; then
                BUILDS=$(cut -d ',' -f 2 "$HOME"/.kerl/otp_builds)
            fi
            COMPREPLY=( $( compgen -W "$BUILDS" -- "$cur") )
            ;;
         deploy)
            if [ "$COMP_CWORD" -eq 3 ]; then
                if [ -f "$HOME"/.kerl/otp_installations ]; then
                    PATHS=$(cut -d ' ' -f 2 "$HOME"/.kerl/otp_installations)
                fi
            fi
            COMPREPLY=( $( compgen -W "$PATHS" -- "$cur") )
            ;;
        delete)
            COMPREPLY=( $( compgen -W "build installation $words" -- "$cur") )
            ;;
        update)
            COMPREPLY=( $( compgen -W "releases" -- "$cur") )
            ;;
        *)
            if [ "$COMP_CWORD" -eq 3 ]; then
                if [ -f "$HOME"/.kerl/otp_builds ]; then
                    BUILDS=$(cut -d ',' -f 2 "$HOME"/.kerl/otp_builds)
                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