udevadm 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. # udevadm(8) completion -*- shell-script -*-
  2. #
  3. # This file is part of systemd.
  4. #
  5. # Copyright 2010 Ran Benita
  6. #
  7. # systemd is free software; you can redistribute it and/or modify it
  8. # under the terms of the GNU Lesser General Public License as published by
  9. # the Free Software Foundation; either version 2.1 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # systemd is distributed in the hope that it will be useful, but
  13. # WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. # General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU Lesser General Public License
  18. # along with systemd; If not, see <http://www.gnu.org/licenses/>.
  19. __contains_word () {
  20. local w word=$1; shift
  21. for w in "$@"; do
  22. [[ $w = "$word" ]] && return
  23. done
  24. }
  25. __get_all_sysdevs() {
  26. local -a devs=(/sys/bus/*/devices/*/ /sys/class/*/*/)
  27. printf '%s\n' "${devs[@]%/}"
  28. }
  29. _udevadm() {
  30. local i verb comps
  31. local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
  32. local OPTS='-h --help --version --debug'
  33. local verbs=(info trigger settle control monitor hwdb test-builtin test)
  34. for ((i=0; i < COMP_CWORD; i++)); do
  35. if __contains_word "${COMP_WORDS[i]}" "${verbs[@]}" &&
  36. ! __contains_word "${COMP_WORDS[i-1]}" ${OPTS[ARG]}; then
  37. verb=${COMP_WORDS[i]}
  38. break
  39. fi
  40. done
  41. if [[ -z $verb ]]; then
  42. COMPREPLY=( $(compgen -W '${OPTS[*]} ${verbs[*]}' -- "$cur") )
  43. return 0
  44. fi
  45. case $verb in
  46. 'info')
  47. if [[ $cur = -* ]]; then
  48. comps='--help --query= --path= --name= --root --attribute-walk --export-db --cleanup-db'
  49. else
  50. comps=$( __get_all_sysdevs )
  51. fi
  52. ;;
  53. 'trigger')
  54. comps='--help --verbose --dry-run --type= --action= --subsystem-match=
  55. --subsystem-nomatch= --attr-match= --attr-nomatch= --property-match=
  56. --tag-match= --sysname-match= --parent-match='
  57. ;;
  58. 'settle')
  59. comps='--help --timeout= --seq-start= --seq-end= --exit-if-exists= --quiet'
  60. ;;
  61. 'control')
  62. comps='--help --exit --log-priority= --stop-exec-queue --start-exec-queue
  63. --reload --property= --children-max= --timeout='
  64. ;;
  65. 'monitor')
  66. comps='--help --kernel --udev --property --subsystem-match= --tag-match='
  67. ;;
  68. 'hwdb')
  69. comps='--help --update --test='
  70. ;;
  71. 'test')
  72. if [[ $cur = -* ]]; then
  73. comps='--help --action='
  74. else
  75. comps=$( __get_all_sysdevs )
  76. fi
  77. ;;
  78. 'test-builtin')
  79. comps='blkid btrfs hwdb input_id keyboard kmod net_id net_setup_link path_id usb_id uaccess'
  80. ;;
  81. *)
  82. comps=${VERBS[*]}
  83. ;;
  84. esac
  85. COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
  86. return 0
  87. }
  88. complete -F _udevadm udevadm