## Authors:
##   Ajrat Makhmutov <rauty@altlinux.org>
##
## Copyright (C) 2024-2025  Basealt LLC
##
## This file is part of alterator-kopidel.
##
## alterator-kopidel is free software: you can redistribute it and/or modify it under the terms
## of the GNU General Public License as published by the Free Software Foundation,
## either version 3 of the License, or (at your option) any later version.
##
## alterator-kopidel is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
## without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
## See the GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License along with alterator-kopidel.
## If not, see <https://www.gnu.org/licenses/>.

_alterator-kopidel(){
	case "$3" in
		-g | --grub-device )
			COMPREPLY=( $(compgen -W "$(alterator-cmdline /grub/devices action list | grep '^name:' | sed 's/^name://')" -- "$2" ))
			boot_mode="$([ -d /sys/firmware/efi ] && echo UEFI || echo legacy )"
			if [ "$boot_mode" == legacy ]; then
				COMPREPLY+=( $(compgen -W root_dev -- "$2" ) )
			fi
		;;
	esac
	# is size of array COMPREPLY equal 0?
	if [ ${#COMPREPLY[@]} -eq 0 ]
	then
		COMPREPLY=( $(compgen -W "--ignored-from --xz --oem-mode --grub-device --help --version" -- "$2") )
	fi
}
complete -o bashdefault -o default -F _alterator-kopidel alterator-kopidel
