From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24353 invoked by alias); 21 Sep 2016 20:17:21 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 39407 Received: (qmail 11514 invoked from network); 21 Sep 2016 20:17:21 -0000 X-Qmail-Scanner-Diagnostics: from nm3-vm4.bullet.mail.ir2.yahoo.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(212.82.96.93):SA:0(0.0/5.0):. Processed in 0.312805 secs); 21 Sep 2016 20:17:21 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=FREEMAIL_FROM,SPF_PASS, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.1 X-Envelope-From: okiddle@yahoo.co.uk X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: pass (ns1.primenet.com.au: SPF record at _spf.mail.yahoo.com designates 212.82.96.93 as permitted sender) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.co.uk; s=s2048; t=1474488620; bh=NTHagGNno9V9afH25ZQjtRKhIQP1vJsHQofki/sk2jY=; h=In-reply-to:From:References:To:cc:Subject:Date:From:Subject; b=b/dLc8SMfpfga9yYU4getssja9aswKFVL+IM16w3VgkZB8BLE7Kz4mOnXkXltmxUM20/4chnxCakrLTD6i0hSlu6W9ysxAWRHuF0jGllAhlsYAUiMAeiNU/7zb8sruHy2Ild5EVGQ/xEZGJY7AVFiAieykv70bGCpt3X0i5QEGzLBHP/IFzt2BN7E5/fSuuLeBSrjUxMEp763fQbZi2mWWS/2pwMflaVH37tzcrF76n45eVysl64lwGi6DYr0PkMWDi1DyPbSdla/WZx1lv76CZZiln//0YM8GiTUo/toRVqTTEIZ3WCkiKhWxeCbwxEcJXnzldaUKDflps1TTEMvA== X-Yahoo-Newman-Id: 78213.60526.bm@smtp118.mail.ir2.yahoo.com X-Yahoo-Newman-Property: ymail-3 X-YMail-OSG: tX0XFGYVM1lee0BRmvjs1MZBSw_O9hzZxlMZKAXaezSDhuQ jOWeNCdcOnYaNy2OIXxecWXHqFiXZKRy0tu8pgpm7yXvNF3oSlwzAQw1Nngd 1.xxpS2hgXJljt29SCk_lYu16y2vzKp9MQcyl8YdgDbuZdL_6lPA0zamUPTq ehNpZ8R3BWw_Klqy2yClnqOd10Ae58ZBlWUHUq67W1fMNLzGXOeBhw5W3iJi UzCUebAbPkudukocGmqs96dhCPV7XcZkPQ1w3KDRfEVvoJ0VXEbmXKVtoXiP t53S62szytGe.3fdEYv5LOfpUHMNuaaA3hzzuF9Uq3I5E3dm6vmXdOd8.Cfm 8OaMbs05SbtB13wAerIBp4ZlnduokSOCdV_v.7CmxMPCOg0BXQolWg7upAUx StU17auailyWvRTA7fwQ5GSk_Dr8gPVmvyWkApUPYxtmjlJxL91eMsAZAG4d EcyqShTenhlK_5XRbkPG_x4ClmZDmm5q5XyqK25KTDF0inF5TObdhNKfIhur 5NUV1RchbeqIpMsIlqkA6BTIPahqKbWMz7bWVKYOMUKM- X-Yahoo-SMTP: opAkk_CswBAce_kJ3nIPlH80cJI- In-reply-to: <16722.1470082775@hydra.kiddle.eu> From: Oliver Kiddle References: <20160731110516.GA20521@pileus.org> <16722.1470082775@hydra.kiddle.eu> To: zsh-workers@zsh.org cc: Andy Spencer Subject: Re: [PATCH] Add completion for cpupower command MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <85088.1474488619.1@hydra.kiddle.eu> Date: Wed, 21 Sep 2016 22:10:19 +0200 Message-ID: <85089.1474488619@hydra.kiddle.eu> On 1 Aug, I wrote: > Thanks for contributing this. I've taken a look and have a few comments. > Mostly all minor points. Following patch implements these comments. I've left the frequency steps alone: it doesn't work on any system I've tried it on but that's probably because my hardware doesn't support it. Newer versions of cpupower list governors in a slightly different format, hence the issue Christian reported. This should now work with both the older format and the newer (at least up to version 4.8). Oliver diff --git a/Completion/Linux/Command/_cpupower b/Completion/Linux/Command/_cpupower index 406893e..6713323 100644 --- a/Completion/Linux/Command/_cpupower +++ b/Completion/Linux/Command/_cpupower @@ -1,102 +1,119 @@ #compdef cpupower -local -a ret state cmds args expl context line +local curcontext="$curcontext" ret=1 +local -a state line expl cmds args +typeset -A opt_args -_arguments \ - '(-h --help)'{-h,--help}'[print usage information]' \ - '(-v --version)'{-v,--version}'[print package name and version]' \ +_arguments -C \ + '(- :)'{-h,--help}'[print help information]' \ + '(- :)'{-v,--version}'[print version information]' \ + '(-d --debug)'{-d,--debug}'[enable debug output]' \ + '(-c --cpu)'{-c,--cpu}'[limit values to specific processor cores]:cpu' \ ':cmd:->cmds' \ '*::arg:->args' && ret=0 +cmds=( + 'frequency-info:show current frequency info' + 'frequency-set:set frequency parameters' + 'idle-info:show current idle state info' + 'idle-set:set idle state parameters' + 'info:show global power parameters' + 'set:set global power parameters' + 'monitor:report frequency and idle statistics' + 'help:print usage information' +) case $state in cmds) - cmds=( - 'frequency-info:show current frequency info' - 'frequency-set:set frequency parameters' - 'idle-info:show current idle state info' - 'idle-set:set idle state parameters' - 'info:show global power parameters' - 'set:set global power parameters' - 'monitor:report frequency and idle statistics' - 'help:print usage information' - ) - _describe cmd cmds && ret=0 + _describe command cmds && ret=0 ;; args) - args=( ) + curcontext="${curcontext%:*}-$words[1]" case ${words[1]} in + help) + _describe command cmds + return + ;; frequency-info) - args+=( - '(-e --debug)'{-e,--debug}'[print debug info]' - '(-f --freq)'{-f,--freq}'[show current frequency]' - '(-w --hwfreq)'{-w,--hwfreq}'[show current hardware frequency]' - '(-l --hwlimits)'{-l,--hwlimits}'[show min/max frequency allowed]' - '(-d --driver)'{-d,--driver}'[show the kernel driver in use]' - '(-p --policy)'{-p,--policy}'[show the current cpufreq policy]' - '(-g --governors)'{-g,--governors}'[show available governers]' - '(-r --related-cpus)'{-a,--related-cpus}'[show cpus that run at the same frequency]' - '(-a --affected-cpus)'{-a,--affected-cpus}'[show software controlled cpus]' - '(-s --stats)'{-s,--stats}'[show cpufreq statistics]' - '(-y --latency)'{-y,--latency}'[show frequency change latency]' - '(-o --proc)'{-o,--proc}'[print old style proc info]' + args=( '(-m --human)'{-m,--human}'[use human readable output]' '(-n --no-rounding)'{-n,--no-rounding}'[disable rounding of values]' + - '(info)' + {-e,--debug}'[print debug info]' + {-f,--freq}'[show current frequency]' + {-w,--hwfreq}'[show current hardware frequency]' + {-l,--hwlimits}'[show min/max frequency allowed]' + {-d,--driver}'[show the kernel driver in use]' + {-p,--policy}'[show the current cpufreq policy]' + {-g,--governors}'[show available governers]' + {-r,--related-cpus}'[show cpus that run at the same frequency]' + {-a,--affected-cpus}'[show software controlled cpus]' + {-s,--stats}'[show cpufreq statistics]' + {-y,--latency}'[show frequency change latency]' ) - ;; + [[ -n $opt_args[(i)-(c|-cpu)] ]] || args+=( + {-o,--proc}'[print old style proc info]' + ) + ;; frequency-set) - args+=( - '(-d --min)'{-d,--min}'[new minimum frequency]:freq:->freq' - '(-u --max)'{-u,--max}'[new maximum frequency]:freq:->freq' - '(-g --governor)'{-g,--governor}'[new cpufreq governor]:gov:->gov' - '(-f --freq)'{-f,--freq}'[new frequency for userspace governor]:freq->freq' + args=( + '(-d --min)'{-d+,--min}'[new minimum frequency]:frequency:->frequencies' + '(-u --max)'{-u+,--max}'[new maximum frequency]:frequency:->frequencies' + '(-g --governor)'{-g+,--governor}'[new cpufreq governor]:governor:->governors' + '(-)'{-f+,--freq}'[new frequency for userspace governor]:frequency:->frequencies' '(-r --related)'{-r,--related}'[modify all hardware related cpus]' ) - ;; + ;; idle-info) - args+=( + args=( '(-f --silent)'{-f,--silent}'[print summary only]' - '(-e --proc)'{-e,--proc}'[print old style proc info]' + '(-e --proc)'{-e,--proc}'[print old style proc info (deprecated)]' ) - ;; + ;; idle-set) - args+=( - '(-d --disable)'{-d,--disable}'[disable specific sleep state]:stateno' - '(-e --enable)'{-e,--enable}'[enable specific sleep state]:stateno' - '(-D --disable-by-latency)'{-D,--disable-by-latency}'[disable state based on latency]:latency' + args=( + '(-d --disable)'{-d+,--disable}'[disable specific sleep state]:state no' + '(-e --enable)'{-e+,--enable}'[enable specific sleep state]:state no' + '(-D --disable-by-latency)'{-D+,--disable-by-latency}'[disable state based on latency]:latency' '(-E --enable-all)'{-E,--enable-all}'[enable all idle states]' ) - ;; + ;; info) - args+=( + args=( '(-b --perf-bias)'{-b,--perf-bias}'[show intel performance bias value]' ) - ;; + ;; set) - args+=( - '(-b --perf-bias)'{-b,--perf-bias}'[set intel performance bias value]:pbias' + args=( + '(-b --perf-bias)'{-b+,--perf-bias}'[set intel performance bias value]:performance bias' ) - ;; + ;; monitor) - args+=( - '-l[list available monitors]' - '-m[display the given monitors]:mon' - '-i[mesurement interval]:secs' + args=( + '(-)-l[list available monitors]' + '-m+[display specified monitors]:monitor:->monitors' + '-i+[measurement interval]:interval (seconds)' '-c[schedule on every core]' '-v[increase verbosity]' + '*:::command: _normal' ) - ;; + ;; esac - _arguments "${args[@]}" && ret=0 + _arguments -C -s "$args[@]" && ret=0 case $state in - freq) - compadd $(cpupower frequency-info | - sed -n 's/ //g; s/,/ /g; s/availablefrequencysteps://p') - ;; - gov) - compadd $(cpupower frequency-info -g | sed 1d) - ;; + frequencies) + _wanted -x frequencies expl frequency compadd $(cpupower frequency-info | + sed -n 's/ //g; s/,/ /g; s/availablefrequencysteps://p') && ret=0 + ;; + governors) + _wanted governors expl 'scaling governor' compadd \ + ${=${"$(_call_program governors cpupower frequency-info -g)"}##*:} && ret=0 + ;; + monitors) + _sequence _wanted monitors expl 'monitor' compadd - ${${${(M)${(f)"$(_call_program monitors \ + cpupower monitor -l)"}:#Monitor *}#*\"}%%\"*} && ret=0 + ;; esac - ;; + ;; esac return ret