# -*- mode: sh; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
# vim: et sts=4 sw=4

#  SPDX-License-Identifier: LGPL-2.1+
#
#  Copyright © 2020-2021 Collabora Ltd.
#  Copyright © 2020-2021 Valve Corporation.
#
#  This file is part of steamos-customizations.
#
#  steamos-customizations is free software; you can redistribute it and/or
#  modify it under the terms of the GNU Lesser General Public License as
#  published by the Free Software Foundation; either version 2.1 of the License,
#  or (at your option) any later version.

_steamos-reboot()
{
    local cur prev words cword
    _init_completion || return

    case "$prev" in
        --next|--reboot-to-firmware-entry)
            local IFS=$'\n'
            local entries
            mapfile -t entries < <(steamos-reboot --list-firmware-entries)
            COMPREPLY=($(compgen -W "${entries[*]// /\\\\ }" -- "${cur// /\\\\ }"))
            return
            ;;
        --reboot-to-bootloader-entry)
            local entries
            mapfile -t entries < <(steamos-reboot --list-bootloader-entries)
            COMPREPLY=($(compgen -W "${entries[*]}" -- "$cur"))
            return
            ;;
        --reboot-to-bootloader-menu)
            _filedir
            return
            ;;
    esac

    local options
    options=(-h --help --factory-reset --reboot-other --next)
    options+=(--reboot-to-bootloader-entry --reboot-to-bootloader-menu --list-bootloader-entries)
    options+=(--reboot-to-firmware-entry --reboot-to-firmware-setup --list-firmware-entries)
    COMPREPLY=($(compgen -W "${options[*]}" -- "$cur"))
} &&
complete -F _steamos-reboot steamos-reboot steamos-halt steamos-poweroff
