1 # udevadm(8) completion -*- shell-script -*-
2 # SPDX-License-Identifier: LGPL-2.1-or-later
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 --value'
53 [INFO_ARG]='-q --query -p --path -n --name -P --export-prefix -d --device-id-of-file --property'
54 [TRIGGER_STANDALONE]='-v --verbose -n --dry-run -q --quiet -w --settle --wait-daemon --uuid
55 --initialized-match --initialized-nomatch'
56 [TRIGGER_ARG]='-t --type -c --action -s --subsystem-match -S --subsystem-nomatch
57 -a --attr-match -A --attr-nomatch -p --property-match
58 -g --tag-match -y --sysname-match --name-match -b --parent-match
59 --prioritized-subsystem'
60 [SETTLE]='-t --timeout -E --exit-if-exists'
61 [CONTROL_STANDALONE]='-e --exit -s --stop-exec-queue -S --start-exec-queue -R --reload --ping'
62 [CONTROL_ARG]='-l --log-priority -p --property -m --children-max -t --timeout'
63 [MONITOR_STANDALONE]='-k --kernel -u --udev -p --property'
64 [MONITOR_ARG]='-s --subsystem-match -t --tag-match'
65 [TEST]='-a --action -N --resolve-names'
66 [TEST_BUILTIN]='-a --action'
69 local verbs=(info trigger settle control monitor test-builtin test)
70 local builtins=(blkid btrfs hwdb input_id keyboard kmod net_id net_setup_link path_id usb_id uaccess)
72 for ((i=0; i < COMP_CWORD; i++)); do
73 if __contains_word "${COMP_WORDS[i]}" "${verbs[@]}"; then
79 if [[ -z ${verb-} ]]; then
80 if [[ "$cur" = -* ]]; then
81 COMPREPLY=( $(compgen -W '${OPTS[COMMON]} ${OPTS[DEBUG]}' -- "$cur") )
83 COMPREPLY=( $(compgen -W '${verbs[*]}' -- "$cur") )
90 if __contains_word "$prev" ${OPTS[INFO_ARG]}; then
93 comps='name symlink path property all'
96 comps=$( __get_all_sysdevs )
100 comps=$( __get_all_devs )
106 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
110 if [[ $cur = -* ]]; then
111 comps="${OPTS[COMMON]} ${OPTS[INFO_STANDALONE]} ${OPTS[INFO_ARG]}"
113 comps=$( __get_all_sysdevs; __get_all_device_units )
119 if __contains_word "$prev" ${OPTS[TRIGGER_ARG]}; then
122 comps='all devices subsystems'
125 comps=$( udevadm trigger --action help )
127 -y|--sysname-match|-b|--parent-match)
128 comps=$( __get_all_sysdevs )
132 comps=$( __get_all_devs )
138 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
142 if [[ $cur = -* ]]; then
143 comps="${OPTS[COMMON]} ${OPTS[TRIGGER_STANDALONE]} ${OPTS[TRIGGER_ARG]}"
145 comps=$( __get_all_sysdevs; __get_all_device_units )
151 if __contains_word "$prev" ${OPTS[SETTLE]}; then
154 comps=$( compgen -A file -- "$cur" )
160 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
164 comps="${OPTS[COMMON]} ${OPTS[SETTLE]}"
168 if __contains_word "$prev" ${OPTS[CONTROL_ARG]}; then
171 comps='alert crit debug emerg err info notice warning'
177 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
181 comps="${OPTS[COMMON]} ${OPTS[CONTROL_STANDALONE]} ${OPTS[CONTROL_ARG]}"
185 if __contains_word "$prev" ${OPTS[MONITOR_ARG]}; then
191 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
195 comps="${OPTS[COMMON]} ${OPTS[MONITOR_STANDALONE]} ${OPTS[MONITOR_ARG]}"
199 if __contains_word "$prev" ${OPTS[TEST]}; then
202 comps=$( udevadm test --action help )
205 comps='early late never'
208 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
212 if [[ $cur = -* ]]; then
213 comps="${OPTS[COMMON]} ${OPTS[TEST]}"
215 comps=$( __get_all_sysdevs )
221 if __contains_word "$prev" ${OPTS[TEST_BUILTIN]}; then
224 comps=$( udevadm test-builtin --action help )
227 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
231 for ((i=0; i < COMP_CWORD; i++)); do
232 if __contains_word "${COMP_WORDS[i]}" "${builtins[@]}"; then
233 builtin=${COMP_WORDS[i]}
238 if [[ -z $builtin ]]; then
239 comps="${builtins[@]}"
240 elif [[ $cur = -* ]]; then
241 comps="${OPTS[COMMON]} ${OPTS[TEST_BUILTIN]}"
243 comps=$( __get_all_sysdevs )
253 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
257 complete -F _udevadm udevadm