diff options
Diffstat (limited to 'shell-completion/bash/udevadm')
-rw-r--r-- | shell-completion/bash/udevadm | 97 |
1 files changed, 78 insertions, 19 deletions
diff --git a/shell-completion/bash/udevadm b/shell-completion/bash/udevadm index e5626c9301..02a025ff45 100644 --- a/shell-completion/bash/udevadm +++ b/shell-completion/bash/udevadm @@ -46,6 +46,35 @@ __get_all_devices() { __get_all_device_units } +__get_root() { + local i + + for ((i=0; i < COMP_CWORD; i++)); do + if [[ "${COMP_WORDS[i]}" = --root=* ]]; then + echo "${COMP_WORDS[i]#--root=}" + break + fi + if (( i > 0 )) && [[ "${COMP_WORDS[i-1]}" == "--root" ]]; then + echo "${COMP_WORDS[i]}" + break + fi + done +} + +__get_udev_rules_files() { + local root=$( __get_root ) + + ls "$root"/usr/lib/udev/rules.d/*.rules \ + "$root"/usr/local/lib/udev/rules.d/*.rules \ + "$root"/run/udev/rules.d/*.rules \ + "$root"/etc/udev/rules.d/*.rules 2>/dev/null +} + +__get_udev_rules_names() { + local -a rules=( $( __get_udev_rules_files ) ) + printf '%s\n' "${rules[@]##*/}" +} + _udevadm() { local i verb comps builtin local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]} @@ -66,18 +95,22 @@ _udevadm() { [SETTLE]='-t --timeout -E --exit-if-exists' [CONTROL_STANDALONE]='-e --exit -s --stop-exec-queue -S --start-exec-queue -R --reload --ping --load-credentials' - [CONTROL_ARG]='-l --log-priority -p --property -m --children-max -t --timeout' + [CONTROL_ARG]='-l --log-priority -p --property -m --children-max -t --timeout --trace' [MONITOR_STANDALONE]='-k --kernel -u --udev -p --property' [MONITOR_ARG]='-s --subsystem-match -t --tag-match' - [TEST]='-a --action -N --resolve-names' + [TEST_STANDALONE]='-v --verbose' + [TEST_ARG]='-a --action -N --resolve-names -D --extra-rules-dir' [TEST_BUILTIN]='-a --action' - [VERIFY]='-N --resolve-names --root --no-summary --no-style' + [VERIFY_STANDALONE]='--no-summary --no-style' + [VERIFY_ARG]='-N --resolve-names --root' + [CAT_STANDALONE]='--tldr --config' + [CAT_ARG]='--root' [WAIT]='-t --timeout --initialized=no --removed --settle' [LOCK]='-t --timeout -d --device -b --backing -p --print' ) - local verbs=(info trigger settle control monitor test-builtin test verify wait lock) - local builtins=(blkid btrfs hwdb input_id keyboard kmod net_id net_setup_link path_id usb_id uaccess) + local verbs=(info trigger settle control monitor test-builtin test verify cat wait lock) + local builtins=(blkid btrfs hwdb input_id keyboard kmod net_driver net_id net_setup_link path_id uaccess usb_id) for ((i=0; i < COMP_CWORD; i++)); do if __contains_word "${COMP_WORDS[i]}" "${verbs[@]}"; then @@ -190,6 +223,9 @@ _udevadm() { -l|--log-priority) comps='alert crit debug emerg err info notice warning' ;; + --trace) + comps='yes no' + ;; *) comps='' ;; @@ -216,7 +252,7 @@ _udevadm() { ;; 'test') - if __contains_word "$prev" ${OPTS[TEST]}; then + if __contains_word "$prev" ${OPTS[TEST_ARG]}; then case $prev in -a|--action) comps=$( udevadm test --action help ) @@ -224,13 +260,12 @@ _udevadm() { -N|--resolve-names) comps='early late never' ;; + -D|--extra-rules-dir) + comps='' + compopt -o dirnames esac - COMPREPLY=( $(compgen -W '$comps' -- "$cur") ) - return 0 - fi - - if [[ $cur = -* ]]; then - comps="${OPTS[COMMON]} ${OPTS[TEST]}" + elif [[ $cur = -* ]]; then + comps="${OPTS[COMMON]} ${OPTS[TEST_ARG]} ${OPTS[TEST_STANDALONE]}" else comps=$( __get_all_devices ) local IFS=$'\n' @@ -266,27 +301,51 @@ _udevadm() { ;; 'verify') - if __contains_word "$prev" ${OPTS[VERIFY]}; then + if __contains_word "$prev" ${OPTS[VERIFY_ARG]}; then case $prev in -N|--resolve-names) comps='early never' ;; --root) - comps=$(compgen -A directory -- "$cur" ) + comps='' compopt -o dirnames ;; *) comps='' ;; esac - COMPREPLY=( $(compgen -W '$comps' -- "$cur") ) - return 0 + elif [[ $cur = -* ]]; then + comps="${OPTS[COMMON]} ${OPTS[VERIFY_ARG]} ${OPTS[VERIFY_STANDALONE]}" + elif [[ $cur = */* ]]; then + comps=$( __get_udev_rules_files ) + compopt -o dirnames + else + comps=$( __get_udev_rules_names ) + compopt -o default fi + ;; - if [[ $cur = -* ]]; then - comps="${OPTS[COMMON]} ${OPTS[VERIFY]}" + 'cat') + if __contains_word "$prev" ${OPTS[CAT_ARG]}; then + case $prev in + --root) + comps='' + compopt -o dirnames + ;; + *) + comps='' + ;; + esac + elif [[ $cur = -* ]]; then + comps="${OPTS[COMMON]} ${OPTS[CAT_ARG]} ${OPTS[CAT_STANDALONE]}" + elif __contains_word "--config" ${COMP_WORDS[*]}; then + comps="${OPTS[COMMON]} ${OPTS[CAT_ARG]} ${OPTS[CAT_STANDALONE]}" + elif [[ $cur = */* ]]; then + comps=$( __get_udev_rules_files ) + compopt -o dirnames else - comps=$( compgen -A file -- "$cur" ) + comps=$( __get_udev_rules_names ) + compopt -o default fi ;; |