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 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 [INFO_ARG]='-q --query -p --path -n --name -P --export-prefix -d --device-id-of-file'
53 [TRIGGER_STANDALONE]='-v --verbose -n --dry-run -w --settle --wait-daemon'
54 [TRIGGER_ARG]='-t --type -c --action -s --subsystem-match -S --subsystem-nomatch
55 -a --attr-match -A --attr-nomatch -p --property-match
56 -g --tag-match -y --sysname-match --name-match -b --parent-match'
57 [SETTLE]='-t --timeout -E --exit-if-exists'
58 [CONTROL_STANDALONE]='-e --exit -s --stop-exec-queue -S --start-exec-queue -R --reload --ping'
59 [CONTROL_ARG]='-l --log-priority -p --property -m --children-max -t --timeout'
60 [MONITOR_STANDALONE]='-k --kernel -u --udev -p --property'
61 [MONITOR_ARG]='-s --subsystem-match -t --tag-match'
62 [TEST]='-a --action -N --resolve-names'
65 local verbs=(info trigger settle control monitor test-builtin test)
66 local builtins=(blkid btrfs hwdb input_id keyboard kmod net_id net_setup_link path_id usb_id uaccess)
68 for ((i=0; i < COMP_CWORD; i++)); do
69 if __contains_word "${COMP_WORDS[i]}" "${verbs[@]}"; then
75 if [[ -z $verb ]]; then
76 if [[ "$cur" = -* ]]; then
77 COMPREPLY=( $(compgen -W '${OPTS[COMMON]} ${OPTS[DEBUG]}' -- "$cur") )
79 COMPREPLY=( $(compgen -W '${verbs[*]}' -- "$cur") )
86 if __contains_word "$prev" ${OPTS[INFO_ARG]}; then
89 comps='name symlink path property all'
92 comps=$( __get_all_sysdevs )
96 comps=$( __get_all_devs )
102 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
106 if [[ $cur = -* ]]; then
107 comps="${OPTS[COMMON]} ${OPTS[INFO_STANDALONE]} ${OPTS[INFO_ARG]}"
109 comps=$( __get_all_sysdevs; __get_all_device_units )
115 if __contains_word "$prev" ${OPTS[TRIGGER_ARG]}; then
118 comps='devices subsystems'
121 comps='add change remove bind unbind'
123 -y|--sysname-match|-b|--parent-match)
124 comps=$( __get_all_sysdevs )
128 comps=$( __get_all_devs )
134 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
138 if [[ $cur = -* ]]; then
139 comps="${OPTS[COMMON]} ${OPTS[TRIGGER_STANDALONE]} ${OPTS[TRIGGER_ARG]}"
141 comps=$( __get_all_sysdevs; __get_all_device_units )
147 if __contains_word "$prev" ${OPTS[SETTLE]}; then
150 comps=$( compgen -A file -- "$cur" )
156 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
160 comps="${OPTS[COMMON]} ${OPTS[SETTLE]}"
164 if __contains_word "$prev" ${OPTS[CONTROL_ARG]}; then
167 comps='alert crit debug emerg err info notice warning'
173 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
177 comps="${OPTS[COMMON]} ${OPTS[CONTROL_STANDALONE]} ${OPTS[CONTROL_ARG]}"
181 if __contains_word "$prev" ${OPTS[MONITOR_ARG]}; then
187 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
191 comps="${OPTS[COMMON]} ${OPTS[MONITOR_STANDALONE]} ${OPTS[MONITOR_ARG]}"
195 if __contains_word "$prev" ${OPTS[TEST]}; then
198 comps='add change remove bind unbind'
201 comps='early late never'
204 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
208 if [[ $cur = -* ]]; then
209 comps="${OPTS[COMMON]} ${OPTS[TEST]}"
211 comps=$( __get_all_sysdevs )
217 for ((i=0; i < COMP_CWORD; i++)); do
218 if __contains_word "${COMP_WORDS[i]}" "${builtins[@]}"; then
219 builtin=${COMP_WORDS[i]}
224 if [[ -z $builtin ]]; then
225 comps="${builtins[@]}"
226 elif [[ $cur = -* ]]; then
227 comps="${OPTS[COMMON]}"
229 comps=$( __get_all_sysdevs )
239 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
243 complete -F _udevadm udevadm