Frederic Weisbecker | 98a4179 | 2012-08-09 16:31:51 +0200 | [diff] [blame] | 1 | # perf completion |
| 2 | |
Namhyung Kim | a1d668c | 2012-10-03 00:21:32 +0900 | [diff] [blame] | 3 | function_exists() |
| 4 | { |
| 5 | declare -F $1 > /dev/null |
| 6 | return $? |
| 7 | } |
| 8 | |
Frederic Weisbecker | 98a4179 | 2012-08-09 16:31:51 +0200 | [diff] [blame] | 9 | have perf && |
| 10 | _perf() |
| 11 | { |
Namhyung Kim | a1d668c | 2012-10-03 00:21:32 +0900 | [diff] [blame] | 12 | local cur prev cmd |
Frederic Weisbecker | 98a4179 | 2012-08-09 16:31:51 +0200 | [diff] [blame] | 13 | |
| 14 | COMPREPLY=() |
Namhyung Kim | a1d668c | 2012-10-03 00:21:32 +0900 | [diff] [blame] | 15 | 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 Weisbecker | 98a4179 | 2012-08-09 16:31:51 +0200 | [diff] [blame] | 21 | |
| 22 | cmd=${COMP_WORDS[0]} |
| 23 | |
Namhyung Kim | 35c2fde | 2012-10-03 00:21:33 +0900 | [diff] [blame] | 24 | # List perf subcommands or long options |
Frederic Weisbecker | 98a4179 | 2012-08-09 16:31:51 +0200 | [diff] [blame] | 25 | if [ $COMP_CWORD -eq 1 ]; then |
Namhyung Kim | 35c2fde | 2012-10-03 00:21:33 +0900 | [diff] [blame] | 26 | 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 Weisbecker | a3277d2 | 2012-08-09 16:31:52 +0200 | [diff] [blame] | 34 | # List possible events for -e option |
| 35 | elif [[ $prev == "-e" && "${COMP_WORDS[1]}" == @(record|stat|top) ]]; then |
Namhyung Kim | 4d8061f | 2012-10-03 00:21:34 +0900 | [diff] [blame^] | 36 | 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 Weisbecker | 98a4179 | 2012-08-09 16:31:51 +0200 | [diff] [blame] | 43 | # Fall down to list regular files |
| 44 | else |
| 45 | _filedir |
| 46 | fi |
| 47 | } && |
| 48 | complete -F _perf perf |