]> git.ipfire.org Git - thirdparty/systemd.git/blob - shell-completion/bash/udevadm
pkgconfig: define variables relative to ${prefix}/${rootprefix}/${sysconfdir}
[thirdparty/systemd.git] / shell-completion / bash / udevadm
1 # udevadm(8) completion -*- shell-script -*-
2 # SPDX-License-Identifier: LGPL-2.1+
3 #
4 # This file is part of systemd.
5 #
6 # Copyright © 2010 Ran Benita
7 #
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.
12 #
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.
17 #
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/>.
20
21 __contains_word () {
22 local w word=$1; shift
23 for w in "$@"; do
24 [[ $w = "$word" ]] && return
25 done
26 }
27
28 __get_all_sysdevs() {
29 local -a devs=(/sys/bus/*/devices/*/ /sys/class/*/*/)
30 printf '%s\n' "${devs[@]%/}"
31 }
32
33 _udevadm() {
34 local i verb comps
35 local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
36 local OPTS='-h --help --version --debug'
37
38 local verbs=(info trigger settle control monitor hwdb test-builtin test)
39
40 for ((i=0; i < COMP_CWORD; i++)); do
41 if __contains_word "${COMP_WORDS[i]}" "${verbs[@]}" &&
42 ! __contains_word "${COMP_WORDS[i-1]}" ${OPTS[ARG]}; then
43 verb=${COMP_WORDS[i]}
44 break
45 fi
46 done
47
48 if [[ -z $verb ]]; then
49 COMPREPLY=( $(compgen -W '${OPTS[*]} ${verbs[*]}' -- "$cur") )
50 return 0
51 fi
52
53 case $verb in
54 'info')
55 if [[ $cur = -* ]]; then
56 comps='--help --query= --path= --name= --root --attribute-walk --export-db --cleanup-db'
57 else
58 comps=$( __get_all_sysdevs )
59 fi
60 ;;
61 'trigger')
62 comps='--help --verbose --dry-run --type= --action= --subsystem-match=
63 --subsystem-nomatch= --attr-match= --attr-nomatch= --property-match=
64 --tag-match= --sysname-match= --parent-match='
65 ;;
66 'settle')
67 comps='--help --timeout= --seq-start= --seq-end= --exit-if-exists= --quiet'
68 ;;
69 'control')
70 comps='--help --exit --log-priority= --stop-exec-queue --start-exec-queue
71 --reload --property= --children-max= --timeout='
72 ;;
73 'monitor')
74 comps='--help --kernel --udev --property --subsystem-match= --tag-match='
75 ;;
76 'hwdb')
77 comps='--help --update --test='
78 ;;
79 'test')
80 if [[ $cur = -* ]]; then
81 comps='--help --action='
82 else
83 comps=$( __get_all_sysdevs )
84 fi
85 ;;
86 'test-builtin')
87 comps='blkid btrfs hwdb input_id keyboard kmod net_id net_setup_link path_id usb_id uaccess'
88 ;;
89 *)
90 comps=${VERBS[*]}
91 ;;
92 esac
93
94 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
95 return 0
96 }
97
98 complete -F _udevadm udevadm