From c8987ab100a1c641cf2c0a970581a2409df9c07c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20PORTAY?= Date: Tue, 5 Apr 2022 14:24:28 +0200 Subject: [PATCH] trivial: Allow mixing modifiers/parameters in bash-completion scripts --- data/bash-completion/fwupdagent | 11 +++--- data/bash-completion/fwupdmgr | 66 ++++++++++----------------------- data/bash-completion/fwupdtool | 52 ++++++++++---------------- 3 files changed, 45 insertions(+), 84 deletions(-) diff --git a/data/bash-completion/fwupdagent b/data/bash-completion/fwupdagent index 5234625da..61becf96a 100644 --- a/data/bash-completion/fwupdagent +++ b/data/bash-completion/fwupdagent @@ -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 } diff --git a/data/bash-completion/fwupdmgr b/data/bash-completion/fwupdmgr index fc299fb91..55a0a71b4 100644 --- a/data/bash-completion/fwupdmgr +++ b/data/bash-completion/fwupdmgr @@ -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 } diff --git a/data/bash-completion/fwupdtool b/data/bash-completion/fwupdtool index de54c97bd..b1ae41ae3 100644 --- a/data/bash-completion/fwupdtool +++ b/data/bash-completion/fwupdtool @@ -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 }