Commit 67afff48 authored by Yunlong Song's avatar Yunlong Song Committed by Arnaldo Carvalho de Melo

perf tools: Fix the bash completion for listing subsubcommands of perf subcommand

The bash completion does not support listing subsubcommands for 'perf
kvm|kmem|mem|lock|sched --<long option> <TAB>', where 'kvm|kmem|mem|
lock|sched' are all subcommands of perf.

Example:

Before this patch:

 $ perf kvm --verbose <TAB>
 $

As shown above, the subsubcommands of perf kvm does not come out.

After this patch:

 $ perf kvm --verbose <TAB>
 buildid-list  diff          record        report        stat
 top

As shown above, the subsubcommands of perf kvm can come out now.
Signed-off-by: default avatarYunlong Song <yunlong.song@huawei.com>
Tested-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/r/1426685758-25488-3-git-send-email-yunlong.song@huawei.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 02fde323
...@@ -100,6 +100,23 @@ __perfcomp_colon () ...@@ -100,6 +100,23 @@ __perfcomp_colon ()
__ltrim_colon_completions $cur __ltrim_colon_completions $cur
} }
__perf_prev_skip_opts ()
{
local i cmd_ cmds_
let i=cword-1
cmds_=$($cmd --list-cmds)
prev_skip_opts=()
while [ $i -ge 0 ]; do
for cmd_ in $cmds_; do
if [[ ${words[i]} == $cmd_ ]]; then
prev_skip_opts=${words[i]}
return
fi
done
((i--))
done
}
__perf_main () __perf_main ()
{ {
local cmd local cmd
...@@ -107,6 +124,8 @@ __perf_main () ...@@ -107,6 +124,8 @@ __perf_main ()
cmd=${words[0]} cmd=${words[0]}
COMPREPLY=() COMPREPLY=()
# Skip options backward and find the last perf command
__perf_prev_skip_opts
# List perf subcommands or long options # List perf subcommands or long options
if [ $cword -eq 1 ]; then if [ $cword -eq 1 ]; then
if [[ $cur == --* ]]; then if [[ $cur == --* ]]; then
...@@ -121,8 +140,8 @@ __perf_main () ...@@ -121,8 +140,8 @@ __perf_main ()
__perfcomp_colon "$evts" "$cur" __perfcomp_colon "$evts" "$cur"
else else
# List subcommands for perf commands # List subcommands for perf commands
if [[ $prev == @(kvm|kmem|mem|lock|sched) ]]; then if [[ $prev_skip_opts == @(kvm|kmem|mem|lock|sched) ]]; then
subcmds=$($cmd $prev --list-cmds) subcmds=$($cmd $prev_skip_opts --list-cmds)
__perfcomp_colon "$subcmds" "$cur" __perfcomp_colon "$subcmds" "$cur"
fi fi
# List long option names # List long option names
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment