1 # shellcheck shell=bash
2 # udevadm(8) completion -*- shell-script -*-
3 # SPDX-License-Identifier: LGPL-2.1-or-later
5 # This file is part of systemd.
7 # Copyright © 2010 Ran Benita
9 # systemd is free software; you can redistribute it and/or modify it
10 # under the terms of the GNU Lesser General Public License as published by
11 # the Free Software Foundation; either version 2.1 of the License, or
12 # (at your option) any later version.
14 # systemd is distributed in the hope that it will be useful, but
15 # WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 # General Public License for more details.
19 # You should have received a copy of the GNU Lesser General Public License
20 # along with systemd; If not, see <https://www.gnu.org/licenses/>.
23 local w word=$1; shift
25 [[ $w = "$word" ]] && return
30 local -a devs=(/sys/bus/*/devices/*/ /sys/class/*/*/)
31 printf '%s\n' "${devs[@]%/}"
36 for i in /dev/* /dev/*/* /dev/*/*/*; do
41 __get_all_device_units() {
42 systemctl list-units -t device --full --no-legend --no-pager --plain 2>/dev/null | \
43 { while read -r a b; do echo "$a"; done; }
47 local i verb comps builtin
48 local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
50 [COMMON]='-h --help -V --version'
52 [INFO_STANDALONE]='-r --root -a --attribute-walk -x --export -e --export-db -c --cleanup-db
53 -w --wait-for-initialization --value'
54 [INFO_ARG]='-q --query -p --path -n --name -P --export-prefix -d --device-id-of-file --property'
55 [TRIGGER_STANDALONE]='-v --verbose -n --dry-run -q --quiet -w --settle --wait-daemon --uuid
56 --initialized-match --initialized-nomatch'
57 [TRIGGER_ARG]='-t --type -c --action -s --subsystem-match -S --subsystem-nomatch
58 -a --attr-match -A --attr-nomatch -p --property-match
59 -g --tag-match -y --sysname-match --name-match -b --parent-match
60 --prioritized-subsystem'
61 [SETTLE]='-t --timeout -E --exit-if-exists'
62 [CONTROL_STANDALONE]='-e --exit -s --stop-exec-queue -S --start-exec-queue -R --reload --ping'
63 [CONTROL_ARG]='-l --log-priority -p --property -m --children-max -t --timeout'
64 [MONITOR_STANDALONE]='-k --kernel -u --udev -p --property'
65 [MONITOR_ARG]='-s --subsystem-match -t --tag-match'
66 [TEST]='-a --action -N --resolve-names'
67 [TEST_BUILTIN]='-a --action'
68 [VERIFY]='-N --resolve-names --root --no-summary --no-style'
69 [WAIT]='-t --timeout --initialized=no --removed --settle'
70 [LOCK]='-t --timeout -d --device -b --backing -p --print'
73 local verbs=(info trigger settle control monitor test-builtin test verify wait lock)
74 local builtins=(blkid btrfs hwdb input_id keyboard kmod net_id net_setup_link path_id usb_id uaccess)
76 for ((i=0; i < COMP_CWORD; i++)); do
77 if __contains_word "${COMP_WORDS[i]}" "${verbs[@]}"; then
83 if [[ -z ${verb-} ]]; then
84 if [[ "$cur" = -* ]]; then
85 COMPREPLY=( $(compgen -W '${OPTS[COMMON]} ${OPTS[DEBUG]}' -- "$cur") )
87 COMPREPLY=( $(compgen -W '${verbs[*]}' -- "$cur") )
94 if __contains_word "$prev" ${OPTS[INFO_ARG]}; then
97 comps='name symlink path property all'
100 comps=$( __get_all_sysdevs )
104 comps=$( __get_all_devs )
110 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
114 if [[ $cur = -* ]]; then
115 comps="${OPTS[COMMON]} ${OPTS[INFO_STANDALONE]} ${OPTS[INFO_ARG]}"
117 comps=$( __get_all_sysdevs; __get_all_device_units )
123 if __contains_word "$prev" ${OPTS[TRIGGER_ARG]}; then
126 comps='all devices subsystems'
129 comps=$( udevadm trigger --action help )
131 -y|--sysname-match|-b|--parent-match)
132 comps=$( __get_all_sysdevs )
136 comps=$( __get_all_devs )
142 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
146 if [[ $cur = -* ]]; then
147 comps="${OPTS[COMMON]} ${OPTS[TRIGGER_STANDALONE]} ${OPTS[TRIGGER_ARG]}"
149 comps=$( __get_all_sysdevs; __get_all_device_units )
155 if __contains_word "$prev" ${OPTS[SETTLE]}; then
158 comps=$( compgen -A file -- "$cur" )
164 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
168 comps="${OPTS[COMMON]} ${OPTS[SETTLE]}"
172 if __contains_word "$prev" ${OPTS[CONTROL_ARG]}; then
175 comps='alert crit debug emerg err info notice warning'
181 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
185 comps="${OPTS[COMMON]} ${OPTS[CONTROL_STANDALONE]} ${OPTS[CONTROL_ARG]}"
189 if __contains_word "$prev" ${OPTS[MONITOR_ARG]}; then
195 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
199 comps="${OPTS[COMMON]} ${OPTS[MONITOR_STANDALONE]} ${OPTS[MONITOR_ARG]}"
203 if __contains_word "$prev" ${OPTS[TEST]}; then
206 comps=$( udevadm test --action help )
209 comps='early late never'
212 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
216 if [[ $cur = -* ]]; then
217 comps="${OPTS[COMMON]} ${OPTS[TEST]}"
219 comps=$( __get_all_sysdevs )
225 if __contains_word "$prev" ${OPTS[TEST_BUILTIN]}; then
228 comps=$( udevadm test-builtin --action help )
231 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
235 for ((i=0; i < COMP_CWORD; i++)); do
236 if __contains_word "${COMP_WORDS[i]}" "${builtins[@]}"; then
237 builtin=${COMP_WORDS[i]}
242 if [[ -z $builtin ]]; then
243 comps="${builtins[@]}"
244 elif [[ $cur = -* ]]; then
245 comps="${OPTS[COMMON]} ${OPTS[TEST_BUILTIN]}"
247 comps=$( __get_all_sysdevs )
253 if __contains_word "$prev" ${OPTS[VERIFY]}; then
259 comps=$(compgen -A directory -- "$cur" )
266 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
270 if [[ $cur = -* ]]; then
271 comps="${OPTS[COMMON]} ${OPTS[VERIFY]}"
273 comps=$( compgen -A file -- "$cur" )
278 if __contains_word "$prev" ${OPTS[WAIT]}; then
284 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
288 if [[ $cur = -* ]]; then
289 comps="${OPTS[COMMON]} ${OPTS[WAIT]}"
291 comps=$( __get_all_devs )
297 if __contains_word "$prev" ${OPTS[LOCK]}; then
303 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
307 if [[ $cur = -* ]]; then
308 comps="${OPTS[COMMON]} ${OPTS[LOCK]}"
319 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
323 complete -F _udevadm udevadm