WIP FPC-III support
[linux/fpc-iii.git] / tools / power / cpupower / cpupower-completion.sh
blobe10839cfcfc17e1c9033c9f73185e0802414a7ac
1 # -*- shell-script -*-
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"
7 _frequency_info ()
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" in
13 frequency-info) COMPREPLY=($(compgen -W "$flags" -- "$cur")) ;;
14 esac
17 _frequency_set ()
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" in
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"))
26 fi ;;
27 -g| --governor)
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"))
30 fi;;
31 frequency-set) COMPREPLY=($(compgen -W "$flags" -- "$cur")) ;;
32 esac
35 _idle_info()
37 local flags="-f --silent"
38 local prev="${COMP_WORDS[COMP_CWORD-1]}"
39 local cur="${COMP_WORDS[COMP_CWORD]}"
40 case "$prev" in
41 idle-info) COMPREPLY=($(compgen -W "$flags" -- "$cur")) ;;
42 esac
45 _idle_set()
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" in
51 idle-set) COMPREPLY=($(compgen -W "$flags" -- "$cur")) ;;
52 esac
55 _set()
57 local flags="--perf-bias, -b"
58 local prev="${COMP_WORDS[COMP_CWORD-1]}"
59 local cur="${COMP_WORDS[COMP_CWORD]}"
60 case "$prev" in
61 set) COMPREPLY=($(compgen -W "$flags" -- "$cur")) ;;
62 esac
65 _monitor()
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" in
71 monitor) COMPREPLY=($(compgen -W "$flags" -- "$cur")) ;;
72 esac
75 _taskset()
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")) ;;
82 esac
83 case "$prev" in
84 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 esac
94 _cpupower ()
96 local i
97 local c=1
98 local command
100 while test $c -lt $COMP_CWORD; do
101 if test $c == 1; then
102 command="${COMP_WORDS[c]}"
104 c=$((++c))
105 done
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]}"))
110 return
113 # Complete arguments to subcommands.
114 case "$command" in
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 ;;
122 set) _set ;;
123 monitor) _monitor ;;
124 esac
127 complete -o bashdefault -o default -F _cpupower cpupower 2>/dev/null \
128 || complete -o default -F _cpupower cpupower