Commit 12f9dd50 authored by Ramkumar Ramachandra's avatar Ramkumar Ramachandra Committed by Arnaldo Carvalho de Melo

perf completion: Factor out compgen stuff

compgen is a bash-builtin; factor out the invocations into a separate
function to give us a chance to override it with a zsh equivalent in
future patches.
Signed-off-by: default avatarRamkumar Ramachandra <artagnon@gmail.com>
Cc: Ingo Molnar <mingo@kernel.org>
Link: http://lkml.kernel.org/r/1384704807-15779-3-git-send-email-artagnon@gmail.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 2cf025e6
...@@ -89,6 +89,11 @@ __ltrim_colon_completions() ...@@ -89,6 +89,11 @@ __ltrim_colon_completions()
fi fi
} }
__perfcomp ()
{
COMPREPLY=( $( compgen -W "$1" -- "$2" ) )
}
__perf_main () __perf_main ()
{ {
local cmd local cmd
...@@ -99,23 +104,23 @@ __perf_main () ...@@ -99,23 +104,23 @@ __perf_main ()
# 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
COMPREPLY=( $( compgen -W '--help --version \ __perfcomp '--help --version \
--exec-path --html-path --paginate --no-pager \ --exec-path --html-path --paginate --no-pager \
--perf-dir --work-tree --debugfs-dir' -- "$cur" ) ) --perf-dir --work-tree --debugfs-dir' -- "$cur"
else else
cmds=$($cmd --list-cmds) cmds=$($cmd --list-cmds)
COMPREPLY=( $( compgen -W '$cmds' -- "$cur" ) ) __perfcomp "$cmds" "$cur"
fi fi
# List possible events for -e option # List possible events for -e option
elif [[ $prev == "-e" && "${words[1]}" == @(record|stat|top) ]]; then elif [[ $prev == "-e" && "${words[1]}" == @(record|stat|top) ]]; then
evts=$($cmd list --raw-dump) evts=$($cmd list --raw-dump)
COMPREPLY=( $( compgen -W '$evts' -- "$cur" ) ) __perfcomp "$evts" "$cur"
__ltrim_colon_completions $cur __ltrim_colon_completions $cur
# List long option names # List long option names
elif [[ $cur == --* ]]; then elif [[ $cur == --* ]]; then
subcmd=${words[1]} subcmd=${words[1]}
opts=$($cmd $subcmd --list-opts) opts=$($cmd $subcmd --list-opts)
COMPREPLY=( $( compgen -W '$opts' -- "$cur" ) ) __perfcomp "$opts" "$cur"
fi fi
} }
......
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