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