blob: 56e6a12aab59b42d4cffbc67858824af818f5fff [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
Namhyung Kimae0c1f92012-10-04 14:23:54 +09009function_exists __ltrim_colon_completions ||
10__ltrim_colon_completions()
11{
12 if [[ "$1" == *:* && "$COMP_WORDBREAKS" == *:* ]]; then
13 # Remove colon-word prefix from COMPREPLY items
14 local colon_word=${1%${1##*:}}
15 local i=${#COMPREPLY[*]}
16 while [[ $((--i)) -ge 0 ]]; do
17 COMPREPLY[$i]=${COMPREPLY[$i]#"$colon_word"}
18 done
19 fi
20}
21
Frederic Weisbecker98a41792012-08-09 16:31:51 +020022have perf &&
23_perf()
24{
Namhyung Kima1d668c2012-10-03 00:21:32 +090025 local cur prev cmd
Frederic Weisbecker98a41792012-08-09 16:31:51 +020026
27 COMPREPLY=()
Namhyung Kima1d668c2012-10-03 00:21:32 +090028 if function_exists _get_comp_words_by_ref; then
Namhyung Kimae0c1f92012-10-04 14:23:54 +090029 _get_comp_words_by_ref -n : cur prev
Namhyung Kima1d668c2012-10-03 00:21:32 +090030 else
Namhyung Kimae0c1f92012-10-04 14:23:54 +090031 cur=$(_get_cword :)
Namhyung Kima1d668c2012-10-03 00:21:32 +090032 prev=${COMP_WORDS[COMP_CWORD-1]}
33 fi
Frederic Weisbecker98a41792012-08-09 16:31:51 +020034
35 cmd=${COMP_WORDS[0]}
36
Namhyung Kim35c2fde2012-10-03 00:21:33 +090037 # List perf subcommands or long options
Frederic Weisbecker98a41792012-08-09 16:31:51 +020038 if [ $COMP_CWORD -eq 1 ]; then
Namhyung Kim35c2fde2012-10-03 00:21:33 +090039 if [[ $cur == --* ]]; then
40 COMPREPLY=( $( compgen -W '--help --version \
41 --exec-path --html-path --paginate --no-pager \
42 --perf-dir --work-tree --debugfs-dir' -- "$cur" ) )
43 else
44 cmds=$($cmd --list-cmds)
45 COMPREPLY=( $( compgen -W '$cmds' -- "$cur" ) )
46 fi
Frederic Weisbeckera3277d22012-08-09 16:31:52 +020047 # List possible events for -e option
48 elif [[ $prev == "-e" && "${COMP_WORDS[1]}" == @(record|stat|top) ]]; then
Namhyung Kim4d8061f2012-10-03 00:21:34 +090049 evts=$($cmd list --raw-dump)
50 COMPREPLY=( $( compgen -W '$evts' -- "$cur" ) )
Namhyung Kimae0c1f92012-10-04 14:23:54 +090051 __ltrim_colon_completions $cur
Namhyung Kim4d8061f2012-10-03 00:21:34 +090052 # List long option names
53 elif [[ $cur == --* ]]; then
54 subcmd=${COMP_WORDS[1]}
55 opts=$($cmd $subcmd --list-opts)
56 COMPREPLY=( $( compgen -W '$opts' -- "$cur" ) )
Frederic Weisbecker98a41792012-08-09 16:31:51 +020057 # Fall down to list regular files
58 else
59 _filedir
60 fi
61} &&
62complete -F _perf perf