1 # udevadm(8) completion -*- shell-script -*-
2 # SPDX-License-Identifier: LGPL-2.1+
4 # This file is part of systemd.
6 # Copyright © 2010 Ran Benita
8 # systemd is free software; you can redistribute it and/or modify it
9 # under the terms of the GNU Lesser General Public License as published by
10 # the Free Software Foundation; either version 2.1 of the License, or
11 # (at your option) any later version.
13 # systemd is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 # General Public License for more details.
18 # You should have received a copy of the GNU Lesser General Public License
19 # along with systemd; If not, see <http://www.gnu.org/licenses/>.
22 local w word=$1; shift
24 [[ $w = "$word" ]] && return
29 local -a devs=(/sys/bus/*/devices/*/ /sys/class/*/*/)
30 printf '%s\n' "${devs[@]%/}"
35 for i in /dev/* /dev/*/*; do
40 __get_all_device_units() {
41 systemctl list-units -t device --full --no-legend --no-pager --plain 2>/dev/null | \
42 { while read -r a b; do echo "$a"; done; }
46 local i verb comps builtin
47 local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
49 [COMMON]='-h --help -V --version'
51 [INFO_STANDALONE]='-r --root -a --attribute-walk -x --export -e --export-db -c --cleanup-db
52 -w --wait-for-initialization'
53 [INFO_ARG]='-q --query -p --path -n --name -P --export-prefix -d --device-id-of-file'
54 [TRIGGER_STANDALONE]='-v --verbose -n --dry-run -w --settle --wait-daemon'
55 [TRIGGER_ARG]='-t --type -c --action -s --subsystem-match -S --subsystem-nomatch
56 -a --attr-match -A --attr-nomatch -p --property-match
57 -g --tag-match -y --sysname-match --name-match -b --parent-match'
58 [SETTLE]='-t --timeout -E --exit-if-exists'
59 [CONTROL_STANDALONE]='-e --exit -s --stop-exec-queue -S --start-exec-queue -R --reload --ping'
60 [CONTROL_ARG]='-l --log-priority -p --property -m --children-max -t --timeout'
61 [MONITOR_STANDALONE]='-k --kernel -u --udev -p --property'
62 [MONITOR_ARG]='-s --subsystem-match -t --tag-match'
63 [TEST]='-a --action -N --resolve-names'
66 local verbs=(info trigger settle control monitor test-builtin test)
67 local builtins=(blkid btrfs hwdb input_id keyboard kmod net_id net_setup_link path_id usb_id uaccess)
69 for ((i=0; i < COMP_CWORD; i++)); do
70 if __contains_word "${COMP_WORDS[i]}" "${verbs[@]}"; then
76 if [[ -z $verb ]]; then
77 if [[ "$cur" = -* ]]; then
78 COMPREPLY=( $(compgen -W '${OPTS[COMMON]} ${OPTS[DEBUG]}' -- "$cur") )
80 COMPREPLY=( $(compgen -W '${verbs[*]}' -- "$cur") )
87 if __contains_word "$prev" ${OPTS[INFO_ARG]}; then
90 comps='name symlink path property all'
93 comps=$( __get_all_sysdevs )
97 comps=$( __get_all_devs )
103 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
107 if [[ $cur = -* ]]; then
108 comps="${OPTS[COMMON]} ${OPTS[INFO_STANDALONE]} ${OPTS[INFO_ARG]}"
110 comps=$( __get_all_sysdevs; __get_all_device_units )
116 if __contains_word "$prev" ${OPTS[TRIGGER_ARG]}; then
119 comps='devices subsystems'
122 comps=$( udevadm trigger --action help )
124 -y|--sysname-match|-b|--parent-match)
125 comps=$( __get_all_sysdevs )
129 comps=$( __get_all_devs )
135 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
139 if [[ $cur = -* ]]; then
140 comps="${OPTS[COMMON]} ${OPTS[TRIGGER_STANDALONE]} ${OPTS[TRIGGER_ARG]}"
142 comps=$( __get_all_sysdevs; __get_all_device_units )
148 if __contains_word "$prev" ${OPTS[SETTLE]}; then
151 comps=$( compgen -A file -- "$cur" )
157 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
161 comps="${OPTS[COMMON]} ${OPTS[SETTLE]}"
165 if __contains_word "$prev" ${OPTS[CONTROL_ARG]}; then
168 comps='alert crit debug emerg err info notice warning'
174 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
178 comps="${OPTS[COMMON]} ${OPTS[CONTROL_STANDALONE]} ${OPTS[CONTROL_ARG]}"
182 if __contains_word "$prev" ${OPTS[MONITOR_ARG]}; then
188 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
192 comps="${OPTS[COMMON]} ${OPTS[MONITOR_STANDALONE]} ${OPTS[MONITOR_ARG]}"
196 if __contains_word "$prev" ${OPTS[TEST]}; then
199 comps=$( udevadm test --action help )
202 comps='early late never'
205 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
209 if [[ $cur = -* ]]; then
210 comps="${OPTS[COMMON]} ${OPTS[TEST]}"
212 comps=$( __get_all_sysdevs )
218 for ((i=0; i < COMP_CWORD; i++)); do
219 if __contains_word "${COMP_WORDS[i]}" "${builtins[@]}"; then
220 builtin=${COMP_WORDS[i]}
225 if [[ -z $builtin ]]; then
226 comps="${builtins[@]}"
227 elif [[ $cur = -* ]]; then
228 comps="${OPTS[COMMON]}"
230 comps=$( __get_all_sysdevs )
240 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
244 complete -F _udevadm udevadm