chiark / gitweb /
shell-completion: systemctl cat
[elogind.git] / shell-completion / bash / udevadm
1 # udevadm(8) completion                                   -*- shell-script -*-
2 #
3 # This file is part of systemd.
4 #
5 # Copyright 2010 Ran Benita
6 #
7 # systemd is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU Lesser General Public License as published by
9 # the Free Software Foundation; either version 2.1 of the License, or
10 # (at your option) any later version.
11 #
12 # systemd is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # General Public License for more details.
16 #
17 # You should have received a copy of the GNU Lesser General Public License
18 # along with systemd; If not, see <http://www.gnu.org/licenses/>.
19
20 __contains_word () {
21         local w word=$1; shift
22         for w in "$@"; do
23                 [[ $w = "$word" ]] && return
24         done
25 }
26
27 __get_all_sysdevs() {
28         local -a devs=(/sys/bus/*/devices/*/ /sys/class/*/*/)
29         printf '%s\n' "${devs[@]%/}"
30 }
31
32 _udevadm() {
33         local i verb comps
34         local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
35         local OPTS='-h --help --version --debug'
36
37         local verbs=(info trigger settle control monitor hwdb test-builtin test)
38
39         for ((i=0; i <= COMP_CWORD; i++)); do
40                 if __contains_word "${COMP_WORDS[i]}" "${verbs[@]}" &&
41                  ! __contains_word "${COMP_WORDS[i-1]}" ${OPTS[ARG]}; then
42                         verb=${COMP_WORDS[i]}
43                         break
44                 fi
45         done
46
47         if [[ -z $verb ]]; then
48                 COMPREPLY=( $(compgen -W '${OPTS[*]} ${verbs[*]}' -- "$cur") )
49                 return 0
50         fi
51
52         case $verb in
53                 'info')
54                         if [[ $cur = -* ]]; then
55                                 comps='--help --query= --path= --name= --root --attribute-walk --export-db --cleanup-db'
56                         else
57                                 comps=$( __get_all_sysdevs )
58                         fi
59                         ;;
60                 'trigger')
61                         comps='--help --verbose --dry-run --type= --action= --subsystem-match=
62                                --subsystem-nomatch= --attr-match= --attr-nomatch= --property-match=
63                                --tag-match= --sysname-match= --parent-match='
64                         ;;
65                 'settle')
66                         comps='--help --timeout= --seq-start= --seq-end= --exit-if-exists= --quiet'
67                         ;;
68                 'control')
69                         comps='--help --exit --log-priority= --stop-exec-queue --start-exec-queue
70                                --reload --property= --children-max= --timeout='
71                         ;;
72                 'monitor')
73                         comps='--help --kernel --udev --property --subsystem-match= --tag-match='
74                         ;;
75                 'hwdb')
76                         comps='--help --update --test='
77                         ;;
78                 'test')
79                         if [[ $cur = -* ]]; then
80                                 comps='--help --action='
81                         else
82                                 comps=$( __get_all_sysdevs )
83                         fi
84                         ;;
85                 'test-builtin')
86                         comps='blkid btrfs hwdb input_id keyboard kmod net_id net_setup_link path_id usb_id uaccess'
87                         ;;
88                 *)
89                         comps=${VERBS[*]}
90                         ;;
91         esac
92
93         COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
94         return 0
95 }
96
97 complete -F _udevadm udevadm