shell-completion: update bash-completion for udevadm
authorYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 11 Jun 2024 06:19:56 +0000 (15:19 +0900)
committerLuca Boccassi <luca.boccassi@gmail.com>
Tue, 11 Jun 2024 09:35:29 +0000 (10:35 +0100)
- Add missing options.
- Show device nodes when supported.

Closes #33265.

shell-completion/bash/udevadm

index fbbaed001c35edace8bfdf8afe56769146e09a19..05f921cf49dc8a0c53e5a6e25eae201e0e673da5 100644 (file)
@@ -31,7 +31,7 @@ __get_all_sysdevs() {
     printf '%s\n' "${devs[@]%/}"
 }
 
-__get_all_devs() {
+__get_all_device_nodes() {
     local i
     for i in /dev/* /dev/*/* /dev/*/*/*; do
         echo $i
@@ -43,15 +43,23 @@ __get_all_device_units() {
         { while read -r a b; do echo "$a"; done; }
 }
 
+__get_all_devices() {
+    __get_all_sysdevs
+    __get_all_device_nodes
+    __get_all_device_units
+}
+
 _udevadm() {
     local i verb comps builtin
     local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
     local -A OPTS=(
         [COMMON]='-h --help -V --version'
         [DEBUG]='-d --debug'
-        [INFO_STANDALONE]='-r --root -a --attribute-walk -x --export -e --export-db -c --cleanup-db
-                           -w --wait-for-initialization --value'
-        [INFO_ARG]='-q --query -p --path -n --name -P --export-prefix -d --device-id-of-file --property'
+        [INFO_STANDALONE]='-r --root -a --attribute-walk -t --tree -x --export -e --export-db -c --cleanup-db
+                           -w --wait-for-initialization --value --no-pager --initialized-match --initialized-nomatch'
+        [INFO_ARG]='-q --query -p --path -n --name -P --export-prefix -d --device-id-of-file --property
+                    --json --subsystem-match --subsystem-nomatch --attr-match --attr-nomatch --property-match
+                    --tag-match --sysname-match --name-match --parent-match'
         [TRIGGER_STANDALONE]='-v --verbose -n --dry-run -q --quiet -w --settle --wait-daemon --uuid
                               --initialized-match --initialized-nomatch'
         [TRIGGER_ARG]='-t --type -c --action -s --subsystem-match -S --subsystem-nomatch
@@ -59,7 +67,8 @@ _udevadm() {
                        -g --tag-match -y --sysname-match --name-match -b --parent-match
                        --prioritized-subsystem'
         [SETTLE]='-t --timeout -E --exit-if-exists'
-        [CONTROL_STANDALONE]='-e --exit -s --stop-exec-queue -S --start-exec-queue -R --reload --ping'
+        [CONTROL_STANDALONE]='-e --exit -s --stop-exec-queue -S --start-exec-queue -R --reload --ping
+                              --load-credentials'
         [CONTROL_ARG]='-l --log-priority -p --property -m --children-max -t --timeout'
         [MONITOR_STANDALONE]='-k --kernel -u --udev -p --property'
         [MONITOR_ARG]='-s --subsystem-match -t --tag-match'
@@ -101,7 +110,17 @@ _udevadm() {
                         local IFS=$'\n'
                         ;;
                     -n|--name)
-                        comps=$( __get_all_devs )
+                        comps=$( __get_all_device_nodes )
+                        ;;
+                    --json)
+                        comps=$( udevadm info --json=help )
+                        ;;
+                    --parent-match)
+                        comps=$( __get_all_sysdevs )
+                        local IFS=$'\n'
+                        ;;
+                    --name-match)
+                        comps=$( __get_all_device_nodes )
                         ;;
                     *)
                         comps=''
@@ -114,7 +133,7 @@ _udevadm() {
             if [[ $cur = -* ]]; then
                 comps="${OPTS[COMMON]} ${OPTS[INFO_STANDALONE]} ${OPTS[INFO_ARG]}"
             else
-                comps=$( __get_all_sysdevs; __get_all_device_units )
+                comps=$( __get_all_devices )
                 local IFS=$'\n'
             fi
             ;;
@@ -133,7 +152,7 @@ _udevadm() {
                         local IFS=$'\n'
                         ;;
                     --name-match)
-                        comps=$( __get_all_devs )
+                        comps=$( __get_all_device_nodes )
                         ;;
                     *)
                         comps=''
@@ -146,7 +165,7 @@ _udevadm() {
             if [[ $cur = -* ]]; then
                 comps="${OPTS[COMMON]} ${OPTS[TRIGGER_STANDALONE]} ${OPTS[TRIGGER_ARG]}"
             else
-                comps=$( __get_all_sysdevs; __get_all_device_units )
+                comps=$( __get_all_devices )
                 local IFS=$'\n'
             fi
             ;;
@@ -216,7 +235,7 @@ _udevadm() {
             if [[ $cur = -* ]]; then
                 comps="${OPTS[COMMON]} ${OPTS[TEST]}"
             else
-                comps=$( __get_all_sysdevs )
+                comps=$( __get_all_devices )
                 local IFS=$'\n'
             fi
             ;;
@@ -244,7 +263,7 @@ _udevadm() {
             elif [[ $cur = -* ]]; then
                 comps="${OPTS[COMMON]} ${OPTS[TEST_BUILTIN]}"
             else
-                comps=$( __get_all_sysdevs )
+                comps=$( __get_all_devices )
                 local IFS=$'\n'
             fi
             ;;
@@ -288,7 +307,7 @@ _udevadm() {
             if [[ $cur = -* ]]; then
                 comps="${OPTS[COMMON]} ${OPTS[WAIT]}"
             else
-                comps=$( __get_all_devs )
+                comps=$( __get_all_devices )
                 local IFS=$'\n'
             fi
             ;;