Add bash-completion for BIOS settings

This commit is contained in:
Mario Limonciello 2022-08-11 09:03:06 -05:00 committed by Mario Limonciello
parent 2536bf462c
commit 088397618a

View File

@ -63,6 +63,27 @@ _fwupdmgr_opts=(
'--json' '--json'
) )
bios_get_opts=(
'--no-authenticate'
'--json'
'--verbose'
)
bios_set_opts=(
'--no-reboot-check'
'--verbose'
)
_show_bios_get_modifiers()
{
COMPREPLY+=( $(compgen -W '${bios_get_opts[@]}' -- "$cur") )
}
_show_bios_set_modifiers()
{
COMPREPLY+=( $(compgen -W '${bios_set_opts[@]}' -- "$cur") )
}
_show_filters() _show_filters()
{ {
local flags local flags
@ -75,6 +96,26 @@ _show_modifiers()
COMPREPLY+=( $(compgen -W '${_fwupdmgr_opts[@]}' -- "$cur") ) COMPREPLY+=( $(compgen -W '${_fwupdmgr_opts[@]}' -- "$cur") )
} }
_show_bios_attrs()
{
if ! command -v jq &> /dev/null; then
return 0
fi
local attr
attr="$(command fwupdmgr get-bios-setting --json --no-authenticate 2>/dev/null | jq '.BiosAttributes | .[] | .Name')"
COMPREPLY+=( $(compgen -W "${attr}" -- "$cur") )
}
_show_bios_attrs_possible()
{
if ! command -v jq &> /dev/null; then
return 0
fi
local attr
attr="$(command fwupdmgr get-bios-setting "$1" --json --no-authenticate 2>/dev/null | jq '.BiosAttributes | .[] | .BiosAttrPossibleValues | .[]')"
COMPREPLY+=( $(compgen -W "${attr}" -- "$cur") )
}
_show_device_ids() _show_device_ids()
{ {
if ! command -v jq &> /dev/null; then if ! command -v jq &> /dev/null; then
@ -124,6 +165,25 @@ _fwupdmgr()
_show_device_ids _show_device_ids
fi fi
;; ;;
get-bios-settings|get-bios-setting)
#bios attrs (no limit)
_show_bios_attrs
_show_bios_get_modifiers
return 0
;;
set-bios-setting)
#allow setting a single bios attr at a time
if [[ "$args" = "2" ]]; then
_show_bios_attrs
fi
#possible values (only works for enumeration though)
if [[ "$args" = "3" ]]; then
_show_bios_attrs_possible "$prev"
return 0
fi
_show_bios_set_modifiers
return 0
;;
get-details) get-details)
#find files #find files
if [[ "$args" = "2" ]]; then if [[ "$args" = "2" ]]; then