cpupower-completion.sh 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. # -*- shell-script -*-
  2. # bash completion script for cpupower
  3. # Taken from git.git's completion script.
  4. _cpupower_commands="frequency-info frequency-set idle-info idle-set set info monitor"
  5. _frequency_info ()
  6. {
  7. local flags="-f -w -l -d -p -g -a -s -y -o -m -n --freq --hwfreq --hwlimits --driver --policy --governors --related-cpus --affected-cpus --stats --latency --proc --human --no-rounding"
  8. local prev="${COMP_WORDS[COMP_CWORD-1]}"
  9. local cur="${COMP_WORDS[COMP_CWORD]}"
  10. case "$prev" in
  11. frequency-info) COMPREPLY=($(compgen -W "$flags" -- "$cur")) ;;
  12. esac
  13. }
  14. _frequency_set ()
  15. {
  16. local flags="-f -g --freq --governor -d --min -u --max -r --related"
  17. local prev="${COMP_WORDS[COMP_CWORD-1]}"
  18. local cur="${COMP_WORDS[COMP_CWORD]}"
  19. case "$prev" in
  20. -f| --freq | -d | --min | -u | --max)
  21. if [ -d /sys/devices/system/cpu/cpufreq/ ] ; then
  22. COMPREPLY=($(compgen -W '$(cat $(ls -d /sys/devices/system/cpu/cpufreq/policy* | head -1)/scaling_available_frequencies)' -- "$cur"))
  23. fi ;;
  24. -g| --governor)
  25. if [ -d /sys/devices/system/cpu/cpufreq/ ] ; then
  26. COMPREPLY=($(compgen -W '$(cat $(ls -d /sys/devices/system/cpu/cpufreq/policy* | head -1)/scaling_available_governors)' -- "$cur"))
  27. fi;;
  28. frequency-set) COMPREPLY=($(compgen -W "$flags" -- "$cur")) ;;
  29. esac
  30. }
  31. _idle_info()
  32. {
  33. local flags="-f --silent"
  34. local prev="${COMP_WORDS[COMP_CWORD-1]}"
  35. local cur="${COMP_WORDS[COMP_CWORD]}"
  36. case "$prev" in
  37. idle-info) COMPREPLY=($(compgen -W "$flags" -- "$cur")) ;;
  38. esac
  39. }
  40. _idle_set()
  41. {
  42. local flags="-d --disable -e --enable -D --disable-by-latency -E --enable-all"
  43. local prev="${COMP_WORDS[COMP_CWORD-1]}"
  44. local cur="${COMP_WORDS[COMP_CWORD]}"
  45. case "$prev" in
  46. idle-set) COMPREPLY=($(compgen -W "$flags" -- "$cur")) ;;
  47. esac
  48. }
  49. _set()
  50. {
  51. local flags="--perf-bias, -b"
  52. local prev="${COMP_WORDS[COMP_CWORD-1]}"
  53. local cur="${COMP_WORDS[COMP_CWORD]}"
  54. case "$prev" in
  55. set) COMPREPLY=($(compgen -W "$flags" -- "$cur")) ;;
  56. esac
  57. }
  58. _monitor()
  59. {
  60. local flags="-l -m -i -c -v"
  61. local prev="${COMP_WORDS[COMP_CWORD-1]}"
  62. local cur="${COMP_WORDS[COMP_CWORD]}"
  63. case "$prev" in
  64. monitor) COMPREPLY=($(compgen -W "$flags" -- "$cur")) ;;
  65. esac
  66. }
  67. _taskset()
  68. {
  69. local prev_to_prev="${COMP_WORDS[COMP_CWORD-2]}"
  70. local prev="${COMP_WORDS[COMP_CWORD-1]}"
  71. local cur="${COMP_WORDS[COMP_CWORD]}"
  72. case "$prev_to_prev" in
  73. -c|--cpu) COMPREPLY=($(compgen -W "$_cpupower_commands" -- "$cur")) ;;
  74. esac
  75. case "$prev" in
  76. frequency-info) _frequency_info ;;
  77. frequency-set) _frequency_set ;;
  78. idle-info) _idle_info ;;
  79. idle-set) _idle_set ;;
  80. set) _set ;;
  81. monitor) _monitor ;;
  82. esac
  83. }
  84. _cpupower ()
  85. {
  86. local i
  87. local c=1
  88. local command
  89. while test $c -lt $COMP_CWORD; do
  90. if test $c == 1; then
  91. command="${COMP_WORDS[c]}"
  92. fi
  93. c=$((++c))
  94. done
  95. # Complete name of subcommand if the user has not finished typing it yet.
  96. if test $c -eq $COMP_CWORD -a -z "$command"; then
  97. COMPREPLY=($(compgen -W "help -v --version -c --cpu $_cpupower_commands" -- "${COMP_WORDS[COMP_CWORD]}"))
  98. return
  99. fi
  100. # Complete arguments to subcommands.
  101. case "$command" in
  102. -v|--version) return ;;
  103. -c|--cpu) _taskset ;;
  104. help) COMPREPLY=($(compgen -W "$_cpupower_commands" -- "${COMP_WORDS[COMP_CWORD]}")) ;;
  105. frequency-info) _frequency_info ;;
  106. frequency-set) _frequency_set ;;
  107. idle-info) _idle_info ;;
  108. idle-set) _idle_set ;;
  109. set) _set ;;
  110. monitor) _monitor ;;
  111. esac
  112. }
  113. complete -o bashdefault -o default -F _cpupower cpupower 2>/dev/null \
  114. || complete -o default -F _cpupower cpupower