2 # bash completion script for cpupower
3 # Taken from git.git's completion script.
5 _cpupower_commands="frequency-info frequency-set idle-info idle-set set info monitor"
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]}"
13 frequency-info) COMPREPLY=($(compgen -W "$flags" -- "$cur")) ;;
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]}"
23 -f| --freq | -d | --min | -u | --max)
24 if [ -d /sys/devices/system/cpu/cpufreq/ ] ; then
25 COMPREPLY=($(compgen -W '$(cat $(ls -d /sys/devices/system/cpu/cpufreq/policy* | head -1)/scaling_available_frequencies)' -- "$cur"))
28 if [ -d /sys/devices/system/cpu/cpufreq/ ] ; then
29 COMPREPLY=($(compgen -W '$(cat $(ls -d /sys/devices/system/cpu/cpufreq/policy* | head -1)/scaling_available_governors)' -- "$cur"))
31 frequency-set) COMPREPLY=($(compgen -W "$flags" -- "$cur")) ;;
37 local flags="-f --silent"
38 local prev="${COMP_WORDS[COMP_CWORD-1]}"
39 local cur="${COMP_WORDS[COMP_CWORD]}"
41 idle-info) COMPREPLY=($(compgen -W "$flags" -- "$cur")) ;;
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]}"
51 idle-set) COMPREPLY=($(compgen -W "$flags" -- "$cur")) ;;
57 local flags="--perf-bias, -b"
58 local prev="${COMP_WORDS[COMP_CWORD-1]}"
59 local cur="${COMP_WORDS[COMP_CWORD]}"
61 set) COMPREPLY=($(compgen -W "$flags" -- "$cur")) ;;
67 local flags="-l -m -i -c -v"
68 local prev="${COMP_WORDS[COMP_CWORD-1]}"
69 local cur="${COMP_WORDS[COMP_CWORD]}"
71 monitor) COMPREPLY=($(compgen -W "$flags" -- "$cur")) ;;
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" in
81 -c|--cpu) COMPREPLY=($(compgen -W "$_cpupower_commands" -- "$cur")) ;;
84 frequency-info) _frequency_info ;;
85 frequency-set) _frequency_set ;;
86 idle-info) _idle_info ;;
87 idle-set) _idle_set ;;
100 while test $c -lt $COMP_CWORD; do
101 if test $c == 1; then
102 command="${COMP_WORDS[c]}"
107 # Complete name of subcommand if the user has not finished typing it yet.
108 if test $c -eq $COMP_CWORD -a -z "$command"; then
109 COMPREPLY=($(compgen -W "help -v --version -c --cpu $_cpupower_commands" -- "${COMP_WORDS[COMP_CWORD]}"))
113 # Complete arguments to subcommands.
115 -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 ;;
127 complete -o bashdefault -o default -F _cpupower cpupower 2>/dev/null \
128 || complete -o default -F _cpupower cpupower