udevadm revision 9d7d42bc406a2ac04639674281ce3ff6beeda790
47be870bd83fb3719dffc3ee9348a409ab762a14Lennart Poettering# udevadm(8) completion -*- shell-script -*-
47be870bd83fb3719dffc3ee9348a409ab762a14Lennart Poettering# This file is part of systemd.
47be870bd83fb3719dffc3ee9348a409ab762a14Lennart Poettering# Copyright 2010 Ran Benita
47be870bd83fb3719dffc3ee9348a409ab762a14Lennart Poettering# systemd is free software; you can redistribute it and/or modify it
47be870bd83fb3719dffc3ee9348a409ab762a14Lennart Poettering# under the terms of the GNU Lesser General Public License as published by
47be870bd83fb3719dffc3ee9348a409ab762a14Lennart Poettering# the Free Software Foundation; either version 2.1 of the License, or
47be870bd83fb3719dffc3ee9348a409ab762a14Lennart Poettering# (at your option) any later version.
47be870bd83fb3719dffc3ee9348a409ab762a14Lennart Poettering# systemd is distributed in the hope that it will be useful, but
47be870bd83fb3719dffc3ee9348a409ab762a14Lennart Poettering# WITHOUT ANY WARRANTY; without even the implied warranty of
47be870bd83fb3719dffc3ee9348a409ab762a14Lennart Poettering# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
47be870bd83fb3719dffc3ee9348a409ab762a14Lennart Poettering# General Public License for more details.
47be870bd83fb3719dffc3ee9348a409ab762a14Lennart Poettering# You should have received a copy of the GNU Lesser General Public License
47be870bd83fb3719dffc3ee9348a409ab762a14Lennart Poettering# along with systemd; If not, see <http://www.gnu.org/licenses/>.
d2134abdd5a21bb7e4b307f403d890901628fcf9Lennart Poettering__contains_word () {
e99e38bbdcca3fe5956823bdb3d38544ccf93221Lennart Poettering local word=$1; shift
47be870bd83fb3719dffc3ee9348a409ab762a14Lennart Poettering for w in $*; do [[ $w = $word ]] && return 0; done
47be870bd83fb3719dffc3ee9348a409ab762a14Lennart Poettering__get_all_sysdevs() {
b60e6bbf67063c6b81b5025d572ebe71aa7ab799Lennart Poettering local -a devs=(/sys/bus/*/devices/*/ /sys/class/*/*/)
47be870bd83fb3719dffc3ee9348a409ab762a14Lennart Poettering printf '%s\n' "${devs[@]%/}"
22be093ffb403a1c474037939ca9b88b1ee39f77Lennart Poettering local i verb comps
d59d0a2b4b41a75eaf618b26b8f8bd1e17de7e2bcee local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
d59d0a2b4b41a75eaf618b26b8f8bd1e17de7e2bcee local OPTS='-h --help --version --debug'
47be870bd83fb3719dffc3ee9348a409ab762a14Lennart Poettering local -A VERBS=(
47be870bd83fb3719dffc3ee9348a409ab762a14Lennart Poettering [TRIGGER]='trigger'
47be870bd83fb3719dffc3ee9348a409ab762a14Lennart Poettering [SETTLE]='settle'
47be870bd83fb3719dffc3ee9348a409ab762a14Lennart Poettering [CONTROL]='control'
47be870bd83fb3719dffc3ee9348a409ab762a14Lennart Poettering [MONITOR]='monitor'
47be870bd83fb3719dffc3ee9348a409ab762a14Lennart Poettering [TESTBUILTIN]='test-builtin'
1c7dde3e475978c569a982d65fd86d4b4e3caad8Bastien Nocera for ((i=0; $i <= $COMP_CWORD; i++)); do
1c7dde3e475978c569a982d65fd86d4b4e3caad8Bastien Nocera if __contains_word "${COMP_WORDS[i]}" ${VERBS[*]} &&
1c7dde3e475978c569a982d65fd86d4b4e3caad8Bastien Nocera ! __contains_word "${COMP_WORDS[i-1]}" ${OPTS[ARG]}; then
1c7dde3e475978c569a982d65fd86d4b4e3caad8Bastien Nocera verb=${COMP_WORDS[i]}
f975e971accc4d50c73ae53167db3df7a7099cf2Lennart Poettering if [[ -z $verb && $cur = -* ]]; then
e9da3678fcfc774b325dc1eaa054d0e00028a1fcLennart Poettering COMPREPLY=( $(compgen -W '${OPTS[*]}' -- "$cur") )
47be870bd83fb3719dffc3ee9348a409ab762a14Lennart Poettering if [[ -z $verb ]]; then
47be870bd83fb3719dffc3ee9348a409ab762a14Lennart Poettering comps=${VERBS[*]}
9a60da2834074d970ca063c210fe9d2f05c70532Thierry Reding elif __contains_word "$verb" ${VERBS[INFO]}; then
f975e971accc4d50c73ae53167db3df7a7099cf2Lennart Poettering if [[ $cur = -* ]]; then
b62cfcea00862ccbf0e5e297f8a339f70987edefMichael Biebl comps='--help --query= --path= --name= --root --attribute-walk --export-db --cleanup-db'
b62cfcea00862ccbf0e5e297f8a339f70987edefMichael Biebl comps=$( __get_all_sysdevs )
be1a67d9d63bfdd4a5f8ba9cfc804030f10f5833Lennart Poettering elif __contains_word "$verb" ${VERBS[TRIGGER]}; then
d1ab0ca07372649dad70a0348d75e394f254e1b6Lennart Poettering comps='--help --verbose --dry-run --type= --action= --subsystem-match=
d1ab0ca07372649dad70a0348d75e394f254e1b6Lennart Poettering --subsystem-nomatch= --attr-match= --attr-nomatch= --property-match=
d1ab0ca07372649dad70a0348d75e394f254e1b6Lennart Poettering --tag-match= --sysname-match= --parent-match='
d1ab0ca07372649dad70a0348d75e394f254e1b6Lennart Poettering elif __contains_word "$verb" ${VERBS[SETTLE]}; then
d1ab0ca07372649dad70a0348d75e394f254e1b6Lennart Poettering comps='--help --timeout= --seq-start= --seq-end= --exit-if-exists= --quiet'
d1ab0ca07372649dad70a0348d75e394f254e1b6Lennart Poettering elif __contains_word "$verb" ${VERBS[CONTROL]}; then
d1ab0ca07372649dad70a0348d75e394f254e1b6Lennart Poettering comps='--help --exit --log-priority= --stop-exec-queue --start-exec-queue
d1ab0ca07372649dad70a0348d75e394f254e1b6Lennart Poettering --reload --property= --children-max= --timeout='
d1ab0ca07372649dad70a0348d75e394f254e1b6Lennart Poettering elif __contains_word "$verb" ${VERBS[MONITOR]}; then
d1ab0ca07372649dad70a0348d75e394f254e1b6Lennart Poettering comps='--help --kernel --udev --property --subsystem-match= --tag-match='
d1ab0ca07372649dad70a0348d75e394f254e1b6Lennart Poettering elif __contains_word "$verb" ${VERBS[HWDB]}; then
d1ab0ca07372649dad70a0348d75e394f254e1b6Lennart Poettering comps='--help --update --test='
d1ab0ca07372649dad70a0348d75e394f254e1b6Lennart Poettering elif __contains_word "$verb" ${VERBS[TEST]}; then
d1ab0ca07372649dad70a0348d75e394f254e1b6Lennart Poettering if [[ $cur = -* ]]; then
d1ab0ca07372649dad70a0348d75e394f254e1b6Lennart Poettering comps='--help --action='
d1ab0ca07372649dad70a0348d75e394f254e1b6Lennart Poettering comps=$( __get_all_sysdevs )
d1ab0ca07372649dad70a0348d75e394f254e1b6Lennart Poettering elif __contains_word "$verb" ${VERBS[TESTBUILTIN]}; then
d1ab0ca07372649dad70a0348d75e394f254e1b6Lennart Poettering comps='blkid btrfs hwdb input_id keyboard kmod net_id path_id usb_id uaccess'
be1a67d9d63bfdd4a5f8ba9cfc804030f10f5833Lennart Poettering COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
d1ab0ca07372649dad70a0348d75e394f254e1b6Lennart Poetteringcomplete -F _udevadm udevadm