]>
Commit | Line | Data |
---|---|---|
d611dadc | 1 | # udevadm(8) completion -*- shell-script -*- |
7059062c | 2 | # SPDX-License-Identifier: LGPL-2.1+ |
d611dadc MB |
3 | # |
4 | # This file is part of systemd. | |
5 | # | |
96b2fb93 | 6 | # Copyright © 2010 Ran Benita |
d611dadc MB |
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 () { | |
a72d698d DR |
22 | local w word=$1; shift |
23 | for w in "$@"; do | |
24 | [[ $w = "$word" ]] && return | |
25 | done | |
d611dadc MB |
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 | ||
b5b7ea75 | 38 | local verbs=(info trigger settle control monitor hwdb test-builtin test) |
d611dadc | 39 | |
3ce09b7d | 40 | for ((i=0; i < COMP_CWORD; i++)); do |
b5b7ea75 | 41 | if __contains_word "${COMP_WORDS[i]}" "${verbs[@]}" && |
d611dadc MB |
42 | ! __contains_word "${COMP_WORDS[i-1]}" ${OPTS[ARG]}; then |
43 | verb=${COMP_WORDS[i]} | |
44 | break | |
45 | fi | |
46 | done | |
47 | ||
b5b7ea75 DR |
48 | if [[ -z $verb ]]; then |
49 | COMPREPLY=( $(compgen -W '${OPTS[*]} ${verbs[*]}' -- "$cur") ) | |
d611dadc MB |
50 | return 0 |
51 | fi | |
52 | ||
b5b7ea75 DR |
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') | |
0b99c9f8 | 87 | comps='blkid btrfs hwdb input_id keyboard kmod net_id net_setup_link path_id usb_id uaccess' |
b5b7ea75 DR |
88 | ;; |
89 | *) | |
90 | comps=${VERBS[*]} | |
91 | ;; | |
92 | esac | |
d611dadc MB |
93 | |
94 | COMPREPLY=( $(compgen -W '$comps' -- "$cur") ) | |
95 | return 0 | |
96 | } | |
97 | ||
98 | complete -F _udevadm udevadm |