_live_build_astra() {
    local CUR PREV DIST TASKS
    COMPREPLY=()
    CUR="${COMP_WORDS[COMP_CWORD]}"
    PREV="${COMP_WORDS[COMP_CWORD - 1]}"

    if echo "${COMP_WORDS[@]}" | grep -q -- --distribution; then
        DIST=$(echo ${COMP_WORDS[@]} | sed 's/.* --distribution \([^ ]*\).*/\1/')
    else
        DIST=$(awk -F. '{print $1"."$2}' /etc/astra_version)
    fi

    STANDARD_OPTS="--add-packages --add-packages-list --build-dir --compression --docker --delete-packages --delete-packages-list --help --host-name --keep-cache --keep-image --keep-log --iso --qcow2 --repository --keep-sources-list --raw --replace-packages --replace-packages-list --remove-sources --tar --version --vmdk --wsl --user-name --no-autologin --distribution --no-autologin --tasks"
    DISTRIBUTION_OPTS="1.8_x86-64 4.8_arm 1.7_x86-64 4.7_arm"

    if [[ "${DIST}" == "1.8"* || "${DIST}" == "4.8"* ]]; then
        TASKS="Fly Internet Office Graphics Multimedia Virtualization Games Base Ufw Fly-qml Fly-ssh"
    elif [[ "${DIST}" == "1.7"* || "${DIST}" == "4.7"* ]]; then
        TASKS="Fly Internet Office Graphics Multimedia Fly-virtualization Games Base Ufw Fly-qml Fly-ssh"
    fi

    if [[ ${PREV} == --distribution ]]; then
        COMPREPLY=($(compgen -W "${DISTRIBUTION_OPTS}" -- ${CUR}))
    elif [[ ${PREV} == --tasks ]]; then
        COMPREPLY=($(compgen -W "${TASKS}" -- ${CUR}))
    elif [[ ${PREV} == --add-packages || ${PREV} == --add-packages-list || ${PREV} == --build-dir || ${PREV} == --delete-packages-list || ${PREV} == --replace-packages-list ]]; then
        COMPREPLY=($(compgen -f ${CUR}))
    else
        COMPREPLY=($(compgen -W "${STANDARD_OPTS}" -- ${CUR}))
    fi

    return 0
}
complete -F _live_build_astra live-build-astra
