blob: 5c355ababf80978c719503f90b58423364e887ec [file] [log] [blame]
Frederic Weisbecker98a41792012-08-09 16:31:51 +02001# perf completion
2
Namhyung Kima1d668c2012-10-03 00:21:32 +09003function_exists()
4{
5 declare -F $1 > /dev/null
6 return $?
7}
8
Frederic Weisbecker98a41792012-08-09 16:31:51 +02009have perf &&
10_perf()
11{
Namhyung Kima1d668c2012-10-03 00:21:32 +090012 local cur prev cmd
Frederic Weisbecker98a41792012-08-09 16:31:51 +020013
14 COMPREPLY=()
Namhyung Kima1d668c2012-10-03 00:21:32 +090015 if function_exists _get_comp_words_by_ref; then
16 _get_comp_words_by_ref cur prev
17 else
18 cur=$(_get_cword)
19 prev=${COMP_WORDS[COMP_CWORD-1]}
20 fi
Frederic Weisbecker98a41792012-08-09 16:31:51 +020021
22 cmd=${COMP_WORDS[0]}
23
Namhyung Kim35c2fde2012-10-03 00:21:33 +090024 # List perf subcommands or long options
Frederic Weisbecker98a41792012-08-09 16:31:51 +020025 if [ $COMP_CWORD -eq 1 ]; then
Namhyung Kim35c2fde2012-10-03 00:21:33 +090026 if [[ $cur == --* ]]; then
27 COMPREPLY=( $( compgen -W '--help --version \
28 --exec-path --html-path --paginate --no-pager \
29 --perf-dir --work-tree --debugfs-dir' -- "$cur" ) )
30 else
31 cmds=$($cmd --list-cmds)
32 COMPREPLY=( $( compgen -W '$cmds' -- "$cur" ) )
33 fi
Frederic Weisbeckera3277d22012-08-09 16:31:52 +020034 # List possible events for -e option
35 elif [[ $prev == "-e" && "${COMP_WORDS[1]}" == @(record|stat|top) ]]; then
Namhyung Kim4d8061f2012-10-03 00:21:34 +090036 evts=$($cmd list --raw-dump)
37 COMPREPLY=( $( compgen -W '$evts' -- "$cur" ) )
38 # List long option names
39 elif [[ $cur == --* ]]; then
40 subcmd=${COMP_WORDS[1]}
41 opts=$($cmd $subcmd --list-opts)
42 COMPREPLY=( $( compgen -W '$opts' -- "$cur" ) )
Frederic Weisbecker98a41792012-08-09 16:31:51 +020043 # Fall down to list regular files
44 else
45 _filedir
46 fi
47} &&
48complete -F _perf perf