aboutsummaryrefslogtreecommitdiffstats
path: root/mageia4arm.bashcompletion
blob: 4cc2b0ce231b1c70667984de777c4a26b70e032c (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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#/usr/bin/env bash
_mageia4arm_completions()
{
    local cur prev commands i PLATFORMS_PATH
    commands="--all --build-path --clean --log --config --target --target-version --mga-version --nonfree --size --tainted --compress --add-checksum --add-urpmimedia --chroot --create-chroot --create-image --help --install-basesystem --jump-chroot --prepare-chroot --sign --update-mirror --desktop --package "
    COMPREPLY=()
    cur=${COMP_WORDS[COMP_CWORD]}
    
    DESKTOP_LIST="cinnamon cinnamon-minimal enlightenment enlightenment-minimal gnome gnome-minimal lxde lxde-minimal lxqt lxqt-minimal mate mate-minimal plasma5 plasma5-minimal sugar windowmaker xfce xfce-minimal fvwm2"
    
    MGA_VERSION_LIST="1 2 3 4 5 6 7 8 cauldron"
    
    if [ -e /usr/share/mageia4arm/platforms ]; then
        if [ -d /usr/share/mageia4arm/platforms ]; then
            PLATFORMS_PATH="/usr/share/mageia4arm/platforms"
        fi
    fi
    if [ -e "$(dirname $(realpath $0))/platforms" ]; then
        if [ -d "$(dirname $(realpath $0))/platforms" ]; then
            PLATFORMS_PATH="$(dirname $(realpath $0) | sed 's/ /\\ /g')/platforms"
        fi
    fi
    if [ -e ./platforms ]; then
        if [ -d ./platforms ]; then
            PLATFORMS_PATH="$(realpath ./platforms | sed 's/ /\\ /g')"
        fi
    fi
    
    if [ "x" != "${PLATFORMS_PATH:="x"}" ]; then
        BOARDS="$(find ./platforms/ -maxdepth 1 -type d | sed -e 's/^\.\/platforms\///' -e '/^$/d' )"
    fi
    
    #First, if command line empty, show all possible commands
    if [[ $COMP_CWORD -eq 1 ]] ; then
        COMPREPLY=( $( compgen -W "${commands}" -- "$cur" ) )
    else
        #then, removes already typed commands from suggestions
        for i in ${commands} ; do
            echo ${COMP_LINE} | grep -e "${i}" &>/dev/null
            if [ 0 -eq ${?} ]; then
                commands="$(echo ${commands} | sed -e "s/$i//" )"
            fi
        done
        
        
        prev=${COMP_WORDS[COMP_CWORD-1]}
        pprev=${COMP_WORDS[COMP_CWORD-2]}
        if [ ${pprev} == "--build-path" ]; then
            prev=jump
        elif [ ${pprev} == "--config" ]; then
            prev=jump
        elif [ ${pprev} == "--desktop" ]; then
            prev=jump
        elif [ ${pprev} == "--mga-version" ]; then
            prev=jump
        elif [ ${pprev} == "--package" ]; then
            prev=jump
        elif [ ${pprev} == "--size" ]; then
            prev=jump
        elif [ ${pprev} == "--target" ]; then
            prev=jump
        elif [ ${pprev} == "--target-version" ]; then
            prev=jump
        fi
        
        
        case $prev in
            --all|--clean|--nonfree|--tainted|--log|--compress|--add-checksum|--add-urpmimedia|--chroot|--create-chroot|--create-image|--help|--install-basesystem|--jump-chroot|--prepare-chroot|--sign|--update-mirror|jump)
                COMPREPLY=( $( compgen -W "${commands} " -- "$cur" ) )
            ;;
            --mga-version)
                COMPREPLY=( $( compgen -W "${MGA_VERSION_LIST}" -- "$cur" ) )
            ;;
            --desktop)
                COMPREPLY=( $( compgen -W "${DESKTOP_LIST}" -- "$cur" ) )
            ;;
            --config)
                echo ${cur} | grep '/' &>/dev/null
                if [ 0 -eq ${?} ]; then
#                     COMPREPLY=( $(compgen -W "$(for d in ${cur}* ${cur}*/*; do [[ -d "$d" ]] && echo $d/; done)" -- ${cur}) )
                    _filedir
                else
                    COMPREPLY=( $( compgen -W "${BOARDS} " -- "$cur" ) )
                fi
            ;;
            --build-path)
                _filedir -d
            ;;
        esac
    fi
}

complete -F _mageia4arm_completions mageia4arm
complete -F _mageia4arm_completions ./create_arm_image.sh

#Not implemented :
#     echo -e "--bootfs               filesystem of boot partition (ext4 or vfat) default: ext4"
#     echo -e "--create-chroot        Create the chroot directory"
#     echo -e "--install-basesystem   install base system"
#     echo -e "--add-urpmimedia       add mirrors for urpmi"
#     echo -e "--chroot               chroot to arm directory and launch packages installation"
#     echo -e "--create-image         Create the image of Mageia ${MAGEIA_VERSION}"