129 lines · bash
1# -*- shell-script -*-2# bash completion script for cpupower3# Taken from git.git's completion script.4 5_cpupower_commands="frequency-info frequency-set idle-info idle-set set info monitor"6 7_frequency_info ()8{9 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"10 local prev="${COMP_WORDS[COMP_CWORD-1]}"11 local cur="${COMP_WORDS[COMP_CWORD]}"12 case "$prev" in13 frequency-info) COMPREPLY=($(compgen -W "$flags" -- "$cur")) ;;14 esac15}16 17_frequency_set ()18{19 local flags="-f -g --freq --governor -d --min -u --max -r --related"20 local prev="${COMP_WORDS[COMP_CWORD-1]}"21 local cur="${COMP_WORDS[COMP_CWORD]}"22 case "$prev" in23 -f| --freq | -d | --min | -u | --max)24 if [ -d /sys/devices/system/cpu/cpufreq/ ] ; then25 COMPREPLY=($(compgen -W '$(cat $(ls -d /sys/devices/system/cpu/cpufreq/policy* | head -1)/scaling_available_frequencies)' -- "$cur"))26 fi ;;27 -g| --governor)28 if [ -d /sys/devices/system/cpu/cpufreq/ ] ; then29 COMPREPLY=($(compgen -W '$(cat $(ls -d /sys/devices/system/cpu/cpufreq/policy* | head -1)/scaling_available_governors)' -- "$cur"))30 fi;;31 frequency-set) COMPREPLY=($(compgen -W "$flags" -- "$cur")) ;;32 esac33}34 35_idle_info()36{37 local flags="-f --silent"38 local prev="${COMP_WORDS[COMP_CWORD-1]}"39 local cur="${COMP_WORDS[COMP_CWORD]}"40 case "$prev" in41 idle-info) COMPREPLY=($(compgen -W "$flags" -- "$cur")) ;;42 esac43}44 45_idle_set()46{47 local flags="-d --disable -e --enable -D --disable-by-latency -E --enable-all"48 local prev="${COMP_WORDS[COMP_CWORD-1]}"49 local cur="${COMP_WORDS[COMP_CWORD]}"50 case "$prev" in51 idle-set) COMPREPLY=($(compgen -W "$flags" -- "$cur")) ;;52 esac53}54 55_set()56{57 local flags="--perf-bias, -b"58 local prev="${COMP_WORDS[COMP_CWORD-1]}"59 local cur="${COMP_WORDS[COMP_CWORD]}"60 case "$prev" in61 set) COMPREPLY=($(compgen -W "$flags" -- "$cur")) ;;62 esac63}64 65_monitor()66{67 local flags="-l -m -i -c -v"68 local prev="${COMP_WORDS[COMP_CWORD-1]}"69 local cur="${COMP_WORDS[COMP_CWORD]}"70 case "$prev" in71 monitor) COMPREPLY=($(compgen -W "$flags" -- "$cur")) ;;72 esac73}74 75_taskset()76{77 local prev_to_prev="${COMP_WORDS[COMP_CWORD-2]}"78 local prev="${COMP_WORDS[COMP_CWORD-1]}"79 local cur="${COMP_WORDS[COMP_CWORD]}"80 case "$prev_to_prev" in81 -c|--cpu) COMPREPLY=($(compgen -W "$_cpupower_commands" -- "$cur")) ;;82 esac83 case "$prev" in84 frequency-info) _frequency_info ;;85 frequency-set) _frequency_set ;;86 idle-info) _idle_info ;;87 idle-set) _idle_set ;;88 set) _set ;;89 monitor) _monitor ;;90 esac91 92}93 94_cpupower ()95{96 local i97 local c=198 local command99 100 while test $c -lt $COMP_CWORD; do101 if test $c == 1; then102 command="${COMP_WORDS[c]}"103 fi104 c=$((++c))105 done106 107 # Complete name of subcommand if the user has not finished typing it yet.108 if test $c -eq $COMP_CWORD -a -z "$command"; then109 COMPREPLY=($(compgen -W "help -v --version -c --cpu $_cpupower_commands" -- "${COMP_WORDS[COMP_CWORD]}"))110 return111 fi112 113 # Complete arguments to subcommands.114 case "$command" in115 -v|--version) return ;;116 -c|--cpu) _taskset ;;117 help) COMPREPLY=($(compgen -W "$_cpupower_commands" -- "${COMP_WORDS[COMP_CWORD]}")) ;;118 frequency-info) _frequency_info ;;119 frequency-set) _frequency_set ;;120 idle-info) _idle_info ;;121 idle-set) _idle_set ;;122 set) _set ;;123 monitor) _monitor ;;124 esac125}126 127complete -o bashdefault -o default -F _cpupower cpupower 2>/dev/null \128 || complete -o default -F _cpupower cpupower129