mirror of
https://git.proxmox.com/git/fwupd
synced 2025-07-24 07:19:29 +00:00
trivial: Allow mixing modifiers/parameters in bash-completion scripts
This commit is contained in:
parent
5bdbf0dd0a
commit
c8987ab100
@ -16,24 +16,25 @@ _show_modifiers()
|
||||
|
||||
_fwupdagent()
|
||||
{
|
||||
local cur prev command
|
||||
local cur prev command args
|
||||
COMPREPLY=()
|
||||
cur=`_get_cword`
|
||||
prev=${COMP_WORDS[COMP_CWORD-1]}
|
||||
command=${COMP_WORDS[1]}
|
||||
_count_args
|
||||
|
||||
case $command in
|
||||
*)
|
||||
#find first command
|
||||
if [[ ${COMP_CWORD} = 1 ]]; then
|
||||
if [[ "$args" = "1" ]]; then
|
||||
COMPREPLY=( $(compgen -W '${_fwupdagent_cmd_list[@]}' -- "$cur") )
|
||||
#modifiers for all commands
|
||||
else
|
||||
_show_modifiers
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
#modifiers
|
||||
_show_modifiers
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
|
@ -102,11 +102,12 @@ _show_remotes()
|
||||
|
||||
_fwupdmgr()
|
||||
{
|
||||
local cur prev command
|
||||
local cur prev command args
|
||||
COMPREPLY=()
|
||||
cur=`_get_cword`
|
||||
prev=${COMP_WORDS[COMP_CWORD-1]}
|
||||
command=${COMP_WORDS[1]}
|
||||
_count_args
|
||||
|
||||
case $prev in
|
||||
--filter)
|
||||
@ -118,114 +119,87 @@ _fwupdmgr()
|
||||
case $command in
|
||||
activate|clear-results|downgrade|get-releases|get-results|unlock|verify|verify-update|get-updates|switch-branch|update|upgrade)
|
||||
#device ID
|
||||
if [[ "$prev" = "$command" ]]; then
|
||||
if [[ "$args" = "2" ]]; then
|
||||
_show_device_ids
|
||||
#modifiers
|
||||
else
|
||||
_show_modifiers
|
||||
fi
|
||||
;;
|
||||
get-details)
|
||||
#find files
|
||||
if [[ "$prev" = "$command" ]]; then
|
||||
if [[ "$args" = "2" ]]; then
|
||||
_filedir
|
||||
#modifiers
|
||||
else
|
||||
_show_modifiers
|
||||
fi
|
||||
;;
|
||||
device-test)
|
||||
#find files
|
||||
if [[ "$prev" = "$command" ]]; then
|
||||
if [[ "$args" = "2" ]]; then
|
||||
_filedir
|
||||
#modifiers
|
||||
else
|
||||
_show_modifiers
|
||||
fi
|
||||
;;
|
||||
install)
|
||||
#device ID
|
||||
if [[ "$prev" = "${COMP_WORDS[2]}" ]]; then
|
||||
if [[ "$args" = "2" ]]; then
|
||||
_show_device_ids
|
||||
#version
|
||||
elif [[ "$prev" = "${COMP_WORDS[3]}" ]]; then
|
||||
elif [[ "$args" = "3" ]]; then
|
||||
_show_release_versions "$prev"
|
||||
#modifiers
|
||||
else
|
||||
_show_modifiers
|
||||
fi
|
||||
;;
|
||||
local-install)
|
||||
#find files
|
||||
if [[ "$prev" = "$command" ]]; then
|
||||
if [[ "$args" = "2" ]]; then
|
||||
_filedir
|
||||
#device ID or modifiers
|
||||
elif [[ "$prev" = "${COMP_WORDS[2]}" ]]; then
|
||||
elif [[ "$args" = "3" ]]; then
|
||||
_show_device_ids
|
||||
_show_modifiers
|
||||
#modifiers
|
||||
else
|
||||
_show_modifiers
|
||||
fi
|
||||
;;
|
||||
modify-remote)
|
||||
#find remotes
|
||||
if [[ "$prev" = "$command" ]]; then
|
||||
if [[ "$args" = "2" ]]; then
|
||||
_show_remotes
|
||||
#add key
|
||||
elif [[ "$prev" = "${COMP_WORDS[2]}" ]]; then
|
||||
elif [[ "$args" = "3" ]]; then
|
||||
local keys
|
||||
keys="$(command fwupdmgr get-remotes | command awk -v pattern="Remote ID:.*${prev}$" '$0~pattern{show=1; next}/Remote/{show=0}{gsub(/:.*/,"")}show')"
|
||||
COMPREPLY+=( $(compgen -W "${keys}" -- "$cur") )
|
||||
#modifiers
|
||||
else
|
||||
_show_modifiers
|
||||
fi
|
||||
;;
|
||||
enable-remote)
|
||||
#find remotes
|
||||
if [[ "$prev" = "$command" ]]; then
|
||||
if [[ "$args" = "2" ]]; then
|
||||
_show_remotes
|
||||
#modifiers
|
||||
else
|
||||
_show_modifiers
|
||||
fi
|
||||
;;
|
||||
disable-remote)
|
||||
#find remotes
|
||||
if [[ "$prev" = "$command" ]]; then
|
||||
if [[ "$args" = "2" ]]; then
|
||||
_show_remotes
|
||||
#modifiers
|
||||
else
|
||||
_show_modifiers
|
||||
fi
|
||||
;;
|
||||
refresh)
|
||||
#find first file
|
||||
if [[ "$prev" = "$command" ]]; then
|
||||
if [[ "$args" = "2" ]]; then
|
||||
_filedir
|
||||
#find second file
|
||||
elif [[ "$prev" = "${COMP_WORDS[2]}" ]]; then
|
||||
elif [[ "$args" = "3" ]]; then
|
||||
_filedir
|
||||
#find remote ID
|
||||
elif [[ "$prev" = "${COMP_WORDS[3]}" ]]; then
|
||||
elif [[ "$args" = "4" ]]; then
|
||||
_show_remotes
|
||||
#modifiers
|
||||
else
|
||||
_show_modifiers
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
#find first command
|
||||
if [[ ${COMP_CWORD} = 1 ]]; then
|
||||
if [[ "$args" = "1" ]]; then
|
||||
COMPREPLY=( $(compgen -W '${_fwupdmgr_cmd_list[@]}' -- "$cur") )
|
||||
#modifiers for all commands
|
||||
else
|
||||
_show_modifiers
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
#modifiers
|
||||
_show_modifiers
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
|
@ -104,11 +104,12 @@ _show_modifiers()
|
||||
|
||||
_fwupdtool()
|
||||
{
|
||||
local cur prev command
|
||||
local cur prev command args
|
||||
COMPREPLY=()
|
||||
cur=`_get_cword`
|
||||
prev=${COMP_WORDS[COMP_CWORD-1]}
|
||||
command=${COMP_WORDS[1]}
|
||||
_count_args
|
||||
|
||||
case $prev in
|
||||
--plugins)
|
||||
@ -124,84 +125,69 @@ _fwupdtool()
|
||||
case $command in
|
||||
get-details|install|install-blob|firmware-dump)
|
||||
#find files
|
||||
if [[ "$prev" = "$command" ]]; then
|
||||
if [[ "$args" = "2" ]]; then
|
||||
_filedir
|
||||
#device ID
|
||||
elif [[ "$prev" = "${COMP_WORDS[2]}" ]]; then
|
||||
elif [[ "$args" = "3" ]]; then
|
||||
_show_device_ids
|
||||
#modifiers
|
||||
else
|
||||
_show_modifiers
|
||||
fi
|
||||
;;
|
||||
attach|detach|activate|verify-update|reinstall|get-updates)
|
||||
#device ID
|
||||
if [[ "$prev" = "$command" ]]; then
|
||||
if [[ "$args" = "2" ]]; then
|
||||
_show_device_ids
|
||||
#modifiers
|
||||
else
|
||||
_show_modifiers
|
||||
fi
|
||||
;;
|
||||
build-firmware)
|
||||
#file in
|
||||
if [[ "$prev" = "$command" ]]; then
|
||||
if [[ "$args" = "2" ]]; then
|
||||
_filedir
|
||||
#file out
|
||||
elif [[ "$prev" = "${COMP_WORDS[2]}" ]]; then
|
||||
elif [[ "$args" = "3" ]]; then
|
||||
_filedir
|
||||
#script
|
||||
elif [[ "$prev" = "${COMP_WORDS[3]}" ]]; then
|
||||
elif [[ "$args" = "4" ]]; then
|
||||
_filedir
|
||||
#output
|
||||
elif [[ "$prev" = "${COMP_WORDS[4]}" ]]; then
|
||||
elif [[ "$args" = "5" ]]; then
|
||||
_filedir
|
||||
#modifiers
|
||||
else
|
||||
_show_modifiers
|
||||
fi
|
||||
;;
|
||||
firmware-parse|firmware-patch)
|
||||
#find files
|
||||
if [[ "$prev" = "$command" ]]; then
|
||||
if [[ "$args" = "2" ]]; then
|
||||
_filedir
|
||||
#firmware_type
|
||||
elif [[ "$prev" = "${COMP_WORDS[2]}" ]]; then
|
||||
elif [[ "$args" = "3" ]]; then
|
||||
_show_firmware_types
|
||||
#modifiers
|
||||
else
|
||||
_show_modifiers
|
||||
fi
|
||||
;;
|
||||
firmware-convert)
|
||||
#file in
|
||||
if [[ "$prev" = "$command" ]]; then
|
||||
if [[ "$args" = "2" ]]; then
|
||||
_filedir
|
||||
#file out
|
||||
elif [[ "$prev" = "${COMP_WORDS[2]}" ]]; then
|
||||
elif [[ "$args" = "3" ]]; then
|
||||
_filedir
|
||||
#firmware_type in
|
||||
elif [[ "$prev" = "${COMP_WORDS[3]}" ]]; then
|
||||
elif [[ "$args" = "4" ]]; then
|
||||
_show_firmware_types
|
||||
#firmware_type out
|
||||
elif [[ "$prev" = "${COMP_WORDS[4]}" ]]; then
|
||||
elif [[ "$args" = "5" ]]; then
|
||||
_show_firmware_types
|
||||
#modifiers
|
||||
else
|
||||
_show_modifiers
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
#find first command
|
||||
if [[ ${COMP_CWORD} = 1 ]]; then
|
||||
if [[ "$args" = "1" ]]; then
|
||||
COMPREPLY=( $(compgen -W '${_fwupdtool_cmd_list[@]}' -- "$cur") )
|
||||
#modifiers for all commands
|
||||
else
|
||||
_show_modifiers
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
#modifiers
|
||||
_show_modifiers
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user