]> git.ipfire.org Git - thirdparty/systemd.git/blob - shell-completion/bash/udevadm
hwdb: Add mapping for Xiaomi Mipad 2 bottom bezel capacitive buttons
[thirdparty/systemd.git] / shell-completion / bash / udevadm
1 # shellcheck shell=bash
2 # udevadm(8) completion -*- shell-script -*-
3 # SPDX-License-Identifier: LGPL-2.1-or-later
4 #
5 # This file is part of systemd.
6 #
7 # Copyright © 2010 Ran Benita
8 #
9 # systemd is free software; you can redistribute it and/or modify it
10 # under the terms of the GNU Lesser General Public License as published by
11 # the Free Software Foundation; either version 2.1 of the License, or
12 # (at your option) any later version.
13 #
14 # systemd is distributed in the hope that it will be useful, but
15 # WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 # General Public License for more details.
18 #
19 # You should have received a copy of the GNU Lesser General Public License
20 # along with systemd; If not, see <https://www.gnu.org/licenses/>.
21
22 __contains_word () {
23 local w word=$1; shift
24 for w in "$@"; do
25 [[ $w = "$word" ]] && return
26 done
27 }
28
29 __get_all_sysdevs() {
30 local -a devs=(/sys/bus/*/devices/*/ /sys/class/*/*/)
31 printf '%s\n' "${devs[@]%/}"
32 }
33
34 __get_all_devs() {
35 local i
36 for i in /dev/* /dev/*/* /dev/*/*/*; do
37 echo $i
38 done
39 }
40
41 __get_all_device_units() {
42 systemctl list-units -t device --full --no-legend --no-pager --plain 2>/dev/null | \
43 { while read -r a b; do echo "$a"; done; }
44 }
45
46 _udevadm() {
47 local i verb comps builtin
48 local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
49 local -A OPTS=(
50 [COMMON]='-h --help -V --version'
51 [DEBUG]='-d --debug'
52 [INFO_STANDALONE]='-r --root -a --attribute-walk -x --export -e --export-db -c --cleanup-db
53 -w --wait-for-initialization --value'
54 [INFO_ARG]='-q --query -p --path -n --name -P --export-prefix -d --device-id-of-file --property'
55 [TRIGGER_STANDALONE]='-v --verbose -n --dry-run -q --quiet -w --settle --wait-daemon --uuid
56 --initialized-match --initialized-nomatch'
57 [TRIGGER_ARG]='-t --type -c --action -s --subsystem-match -S --subsystem-nomatch
58 -a --attr-match -A --attr-nomatch -p --property-match
59 -g --tag-match -y --sysname-match --name-match -b --parent-match
60 --prioritized-subsystem'
61 [SETTLE]='-t --timeout -E --exit-if-exists'
62 [CONTROL_STANDALONE]='-e --exit -s --stop-exec-queue -S --start-exec-queue -R --reload --ping'
63 [CONTROL_ARG]='-l --log-priority -p --property -m --children-max -t --timeout'
64 [MONITOR_STANDALONE]='-k --kernel -u --udev -p --property'
65 [MONITOR_ARG]='-s --subsystem-match -t --tag-match'
66 [TEST]='-a --action -N --resolve-names'
67 [TEST_BUILTIN]='-a --action'
68 [VERIFY]='-N --resolve-names --root --no-summary --no-style'
69 [WAIT]='-t --timeout --initialized=no --removed --settle'
70 [LOCK]='-t --timeout -d --device -b --backing -p --print'
71 )
72
73 local verbs=(info trigger settle control monitor test-builtin test verify wait lock)
74 local builtins=(blkid btrfs hwdb input_id keyboard kmod net_id net_setup_link path_id usb_id uaccess)
75
76 for ((i=0; i < COMP_CWORD; i++)); do
77 if __contains_word "${COMP_WORDS[i]}" "${verbs[@]}"; then
78 verb=${COMP_WORDS[i]}
79 break
80 fi
81 done
82
83 if [[ -z ${verb-} ]]; then
84 if [[ "$cur" = -* ]]; then
85 COMPREPLY=( $(compgen -W '${OPTS[COMMON]} ${OPTS[DEBUG]}' -- "$cur") )
86 else
87 COMPREPLY=( $(compgen -W '${verbs[*]}' -- "$cur") )
88 fi
89 return 0
90 fi
91
92 case $verb in
93 'info')
94 if __contains_word "$prev" ${OPTS[INFO_ARG]}; then
95 case $prev in
96 -q|--query)
97 comps='name symlink path property all'
98 ;;
99 -p|--path)
100 comps=$( __get_all_sysdevs )
101 local IFS=$'\n'
102 ;;
103 -n|--name)
104 comps=$( __get_all_devs )
105 ;;
106 *)
107 comps=''
108 ;;
109 esac
110 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
111 return 0
112 fi
113
114 if [[ $cur = -* ]]; then
115 comps="${OPTS[COMMON]} ${OPTS[INFO_STANDALONE]} ${OPTS[INFO_ARG]}"
116 else
117 comps=$( __get_all_sysdevs; __get_all_device_units )
118 local IFS=$'\n'
119 fi
120 ;;
121
122 'trigger')
123 if __contains_word "$prev" ${OPTS[TRIGGER_ARG]}; then
124 case $prev in
125 -t|--type)
126 comps='all devices subsystems'
127 ;;
128 -c|--action)
129 comps=$( udevadm trigger --action help )
130 ;;
131 -y|--sysname-match|-b|--parent-match)
132 comps=$( __get_all_sysdevs )
133 local IFS=$'\n'
134 ;;
135 --name-match)
136 comps=$( __get_all_devs )
137 ;;
138 *)
139 comps=''
140 ;;
141 esac
142 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
143 return 0
144 fi
145
146 if [[ $cur = -* ]]; then
147 comps="${OPTS[COMMON]} ${OPTS[TRIGGER_STANDALONE]} ${OPTS[TRIGGER_ARG]}"
148 else
149 comps=$( __get_all_sysdevs; __get_all_device_units )
150 local IFS=$'\n'
151 fi
152 ;;
153
154 'settle')
155 if __contains_word "$prev" ${OPTS[SETTLE]}; then
156 case $prev in
157 -E|--exit-if-exists)
158 comps=$( compgen -A file -- "$cur" )
159 ;;
160 *)
161 comps=''
162 ;;
163 esac
164 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
165 return 0
166 fi
167
168 comps="${OPTS[COMMON]} ${OPTS[SETTLE]}"
169 ;;
170
171 'control')
172 if __contains_word "$prev" ${OPTS[CONTROL_ARG]}; then
173 case $prev in
174 -l|--log-priority)
175 comps='alert crit debug emerg err info notice warning'
176 ;;
177 *)
178 comps=''
179 ;;
180 esac
181 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
182 return 0
183 fi
184
185 comps="${OPTS[COMMON]} ${OPTS[CONTROL_STANDALONE]} ${OPTS[CONTROL_ARG]}"
186 ;;
187
188 'monitor')
189 if __contains_word "$prev" ${OPTS[MONITOR_ARG]}; then
190 case $prev in
191 *)
192 comps=''
193 ;;
194 esac
195 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
196 return 0
197 fi
198
199 comps="${OPTS[COMMON]} ${OPTS[MONITOR_STANDALONE]} ${OPTS[MONITOR_ARG]}"
200 ;;
201
202 'test')
203 if __contains_word "$prev" ${OPTS[TEST]}; then
204 case $prev in
205 -a|--action)
206 comps=$( udevadm test --action help )
207 ;;
208 -N|--resolve-names)
209 comps='early late never'
210 ;;
211 esac
212 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
213 return 0
214 fi
215
216 if [[ $cur = -* ]]; then
217 comps="${OPTS[COMMON]} ${OPTS[TEST]}"
218 else
219 comps=$( __get_all_sysdevs )
220 local IFS=$'\n'
221 fi
222 ;;
223
224 'test-builtin')
225 if __contains_word "$prev" ${OPTS[TEST_BUILTIN]}; then
226 case $prev in
227 -a|--action)
228 comps=$( udevadm test-builtin --action help )
229 ;;
230 esac
231 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
232 return 0
233 fi
234
235 for ((i=0; i < COMP_CWORD; i++)); do
236 if __contains_word "${COMP_WORDS[i]}" "${builtins[@]}"; then
237 builtin=${COMP_WORDS[i]}
238 break
239 fi
240 done
241
242 if [[ -z $builtin ]]; then
243 comps="${builtins[@]}"
244 elif [[ $cur = -* ]]; then
245 comps="${OPTS[COMMON]} ${OPTS[TEST_BUILTIN]}"
246 else
247 comps=$( __get_all_sysdevs )
248 local IFS=$'\n'
249 fi
250 ;;
251
252 'verify')
253 if __contains_word "$prev" ${OPTS[VERIFY]}; then
254 case $prev in
255 -N|--resolve-names)
256 comps='early never'
257 ;;
258 --root)
259 comps=$(compgen -A directory -- "$cur" )
260 compopt -o dirnames
261 ;;
262 *)
263 comps=''
264 ;;
265 esac
266 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
267 return 0
268 fi
269
270 if [[ $cur = -* ]]; then
271 comps="${OPTS[COMMON]} ${OPTS[VERIFY]}"
272 else
273 comps=$( compgen -A file -- "$cur" )
274 fi
275 ;;
276
277 'wait')
278 if __contains_word "$prev" ${OPTS[WAIT]}; then
279 case $prev in
280 *)
281 comps=''
282 ;;
283 esac
284 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
285 return 0
286 fi
287
288 if [[ $cur = -* ]]; then
289 comps="${OPTS[COMMON]} ${OPTS[WAIT]}"
290 else
291 comps=$( __get_all_devs )
292 local IFS=$'\n'
293 fi
294 ;;
295
296 'lock')
297 if __contains_word "$prev" ${OPTS[LOCK]}; then
298 case $prev in
299 *)
300 comps=''
301 ;;
302 esac
303 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
304 return 0
305 fi
306
307 if [[ $cur = -* ]]; then
308 comps="${OPTS[COMMON]} ${OPTS[LOCK]}"
309 else
310 comps=''
311 fi
312 ;;
313
314 *)
315 comps=${VERBS[*]}
316 ;;
317 esac
318
319 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
320 return 0
321 }
322
323 complete -F _udevadm udevadm