Path: blob/master/tools/power/cpupower/cpupower-completion.sh
26285 views
# -*- shell-script -*-1# bash completion script for cpupower2# Taken from git.git's completion script.34_cpupower_commands="frequency-info frequency-set idle-info idle-set set info monitor"56_frequency_info ()7{8local 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"9local prev="${COMP_WORDS[COMP_CWORD-1]}"10local cur="${COMP_WORDS[COMP_CWORD]}"11case "$prev" in12frequency-info) COMPREPLY=($(compgen -W "$flags" -- "$cur")) ;;13esac14}1516_frequency_set ()17{18local flags="-f -g --freq --governor -d --min -u --max -r --related"19local prev="${COMP_WORDS[COMP_CWORD-1]}"20local cur="${COMP_WORDS[COMP_CWORD]}"21case "$prev" in22-f| --freq | -d | --min | -u | --max)23if [ -d /sys/devices/system/cpu/cpufreq/ ] ; then24COMPREPLY=($(compgen -W '$(cat $(ls -d /sys/devices/system/cpu/cpufreq/policy* | head -1)/scaling_available_frequencies)' -- "$cur"))25fi ;;26-g| --governor)27if [ -d /sys/devices/system/cpu/cpufreq/ ] ; then28COMPREPLY=($(compgen -W '$(cat $(ls -d /sys/devices/system/cpu/cpufreq/policy* | head -1)/scaling_available_governors)' -- "$cur"))29fi;;30frequency-set) COMPREPLY=($(compgen -W "$flags" -- "$cur")) ;;31esac32}3334_idle_info()35{36local flags="-f --silent"37local prev="${COMP_WORDS[COMP_CWORD-1]}"38local cur="${COMP_WORDS[COMP_CWORD]}"39case "$prev" in40idle-info) COMPREPLY=($(compgen -W "$flags" -- "$cur")) ;;41esac42}4344_idle_set()45{46local flags="-d --disable -e --enable -D --disable-by-latency -E --enable-all"47local prev="${COMP_WORDS[COMP_CWORD-1]}"48local cur="${COMP_WORDS[COMP_CWORD]}"49case "$prev" in50idle-set) COMPREPLY=($(compgen -W "$flags" -- "$cur")) ;;51esac52}5354_set()55{56local flags="--perf-bias, -b"57local prev="${COMP_WORDS[COMP_CWORD-1]}"58local cur="${COMP_WORDS[COMP_CWORD]}"59case "$prev" in60set) COMPREPLY=($(compgen -W "$flags" -- "$cur")) ;;61esac62}6364_monitor()65{66local flags="-l -m -i -c -v"67local prev="${COMP_WORDS[COMP_CWORD-1]}"68local cur="${COMP_WORDS[COMP_CWORD]}"69case "$prev" in70monitor) COMPREPLY=($(compgen -W "$flags" -- "$cur")) ;;71esac72}7374_taskset()75{76local prev_to_prev="${COMP_WORDS[COMP_CWORD-2]}"77local prev="${COMP_WORDS[COMP_CWORD-1]}"78local cur="${COMP_WORDS[COMP_CWORD]}"79case "$prev_to_prev" in80-c|--cpu) COMPREPLY=($(compgen -W "$_cpupower_commands" -- "$cur")) ;;81esac82case "$prev" in83frequency-info) _frequency_info ;;84frequency-set) _frequency_set ;;85idle-info) _idle_info ;;86idle-set) _idle_set ;;87set) _set ;;88monitor) _monitor ;;89esac9091}9293_cpupower ()94{95local i96local c=197local command9899while test $c -lt $COMP_CWORD; do100if test $c == 1; then101command="${COMP_WORDS[c]}"102fi103c=$((++c))104done105106# Complete name of subcommand if the user has not finished typing it yet.107if test $c -eq $COMP_CWORD -a -z "$command"; then108COMPREPLY=($(compgen -W "help -v --version -c --cpu $_cpupower_commands" -- "${COMP_WORDS[COMP_CWORD]}"))109return110fi111112# Complete arguments to subcommands.113case "$command" in114-v|--version) return ;;115-c|--cpu) _taskset ;;116help) COMPREPLY=($(compgen -W "$_cpupower_commands" -- "${COMP_WORDS[COMP_CWORD]}")) ;;117frequency-info) _frequency_info ;;118frequency-set) _frequency_set ;;119idle-info) _idle_info ;;120idle-set) _idle_set ;;121set) _set ;;122monitor) _monitor ;;123esac124}125126complete -o bashdefault -o default -F _cpupower cpupower 2>/dev/null \127|| complete -o default -F _cpupower cpupower128129130