blob: 35fdda1540d8cdc26aaa371909a9d57adb909ce5 [file] [log] [blame]
Frederic Weisbecker98a41792012-08-09 16:31:51 +02001# perf completion
2
Ramkumar Ramachandra4685a6c2013-07-04 18:11:29 +05303type __ltrim_colon_completions &>/dev/null ||
Namhyung Kimae0c1f92012-10-04 14:23:54 +09004__ltrim_colon_completions()
5{
6 if [[ "$1" == *:* && "$COMP_WORDBREAKS" == *:* ]]; then
7 # Remove colon-word prefix from COMPREPLY items
Ramkumar Ramachandra30079d12013-07-04 18:11:26 +05308 local colon_word=${1%"${1##*:}"}
Namhyung Kimae0c1f92012-10-04 14:23:54 +09009 local i=${#COMPREPLY[*]}
10 while [[ $((--i)) -ge 0 ]]; do
11 COMPREPLY[$i]=${COMPREPLY[$i]#"$colon_word"}
12 done
13 fi
14}
15
Ramkumar Ramachandra1ba6e012013-07-04 18:11:25 +053016type perf &>/dev/null &&
Frederic Weisbecker98a41792012-08-09 16:31:51 +020017_perf()
18{
Namhyung Kima1d668c2012-10-03 00:21:32 +090019 local cur prev cmd
Frederic Weisbecker98a41792012-08-09 16:31:51 +020020
21 COMPREPLY=()
Namhyung Kima1d668c2012-10-03 00:21:32 +090022 if function_exists _get_comp_words_by_ref; then
Namhyung Kimae0c1f92012-10-04 14:23:54 +090023 _get_comp_words_by_ref -n : cur prev
Namhyung Kima1d668c2012-10-03 00:21:32 +090024 else
Namhyung Kimae0c1f92012-10-04 14:23:54 +090025 cur=$(_get_cword :)
Namhyung Kima1d668c2012-10-03 00:21:32 +090026 prev=${COMP_WORDS[COMP_CWORD-1]}
27 fi
Frederic Weisbecker98a41792012-08-09 16:31:51 +020028
29 cmd=${COMP_WORDS[0]}
30
Namhyung Kim35c2fde2012-10-03 00:21:33 +090031 # List perf subcommands or long options
Frederic Weisbecker98a41792012-08-09 16:31:51 +020032 if [ $COMP_CWORD -eq 1 ]; then
Namhyung Kim35c2fde2012-10-03 00:21:33 +090033 if [[ $cur == --* ]]; then
34 COMPREPLY=( $( compgen -W '--help --version \
35 --exec-path --html-path --paginate --no-pager \
36 --perf-dir --work-tree --debugfs-dir' -- "$cur" ) )
37 else
38 cmds=$($cmd --list-cmds)
39 COMPREPLY=( $( compgen -W '$cmds' -- "$cur" ) )
40 fi
Frederic Weisbeckera3277d22012-08-09 16:31:52 +020041 # List possible events for -e option
42 elif [[ $prev == "-e" && "${COMP_WORDS[1]}" == @(record|stat|top) ]]; then
Namhyung Kim4d8061f2012-10-03 00:21:34 +090043 evts=$($cmd list --raw-dump)
44 COMPREPLY=( $( compgen -W '$evts' -- "$cur" ) )
Namhyung Kimae0c1f92012-10-04 14:23:54 +090045 __ltrim_colon_completions $cur
Namhyung Kim4d8061f2012-10-03 00:21:34 +090046 # List long option names
47 elif [[ $cur == --* ]]; then
48 subcmd=${COMP_WORDS[1]}
49 opts=$($cmd $subcmd --list-opts)
50 COMPREPLY=( $( compgen -W '$opts' -- "$cur" ) )
Frederic Weisbecker98a41792012-08-09 16:31:51 +020051 fi
52} &&
Ramkumar Ramachandra7b6c48e2013-07-04 18:11:27 +053053
54complete -o bashdefault -o default -o nospace -F _perf perf 2>/dev/null \
55 || complete -o default -o nospace -F _perf perf