_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-rootfs --keep-image --keep-log --iso --qcow2 --repository --keep-sources-list --raw --replace-packages --replace-packages-list --remove-sources --tar --version --vmdk --wsl --user-name --user-password --user-password-hash --no-autologin --distribution --tasks --simulation --quiet --verbose --show-output --config-file --config-only --convert-to-live"
    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} == --compression ]]; then
        COMPREPLY=($(compgen -W "zstd xz lzo lz4 gzip" -- ${CUR}))
    elif [[ ${PREV} == --add-packages || ${PREV} == --add-packages-list || ${PREV} == --build-dir || ${PREV} == -b || ${PREV} == --delete-packages-list || ${PREV} == --replace-packages-list || ${PREV} == --config-file || ${PREV} == --convert-to-live || ${PREV} == --repository || ${PREV} == -r || ${PREV} == -u || ${PREV} == --iso || ${PREV} == -i || ${PREV} == --raw || ${PREV} == -R || ${PREV} == --qcow2 || ${PREV} == -q || ${PREV} == --tar || ${PREV} == -T || ${PREV} == --docker || ${PREV} == -D || ${PREV} == --wsl || ${PREV} == -w ]]; then
        COMPREPLY=($(compgen -f ${CUR}))
    else
        COMPREPLY=($(compgen -W "${STANDARD_OPTS}" -- ${CUR}))
    fi

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