Frederic Weisbecker | 98a4179 | 2012-08-09 16:31:51 +0200 | [diff] [blame] | 1 | # perf completion |
| 2 | |
Ramkumar Ramachandra | 4685a6c | 2013-07-04 18:11:29 +0530 | [diff] [blame^] | 3 | type __ltrim_colon_completions &>/dev/null || |
Namhyung Kim | ae0c1f9 | 2012-10-04 14:23:54 +0900 | [diff] [blame] | 4 | __ltrim_colon_completions() |
| 5 | { |
| 6 | if [[ "$1" == *:* && "$COMP_WORDBREAKS" == *:* ]]; then |
| 7 | # Remove colon-word prefix from COMPREPLY items |
Ramkumar Ramachandra | 30079d1 | 2013-07-04 18:11:26 +0530 | [diff] [blame] | 8 | local colon_word=${1%"${1##*:}"} |
Namhyung Kim | ae0c1f9 | 2012-10-04 14:23:54 +0900 | [diff] [blame] | 9 | local i=${#COMPREPLY[*]} |
| 10 | while [[ $((--i)) -ge 0 ]]; do |
| 11 | COMPREPLY[$i]=${COMPREPLY[$i]#"$colon_word"} |
| 12 | done |
| 13 | fi |
| 14 | } |
| 15 | |
Ramkumar Ramachandra | 1ba6e01 | 2013-07-04 18:11:25 +0530 | [diff] [blame] | 16 | type perf &>/dev/null && |
Frederic Weisbecker | 98a4179 | 2012-08-09 16:31:51 +0200 | [diff] [blame] | 17 | _perf() |
| 18 | { |
Namhyung Kim | a1d668c | 2012-10-03 00:21:32 +0900 | [diff] [blame] | 19 | local cur prev cmd |
Frederic Weisbecker | 98a4179 | 2012-08-09 16:31:51 +0200 | [diff] [blame] | 20 | |
| 21 | COMPREPLY=() |
Namhyung Kim | a1d668c | 2012-10-03 00:21:32 +0900 | [diff] [blame] | 22 | if function_exists _get_comp_words_by_ref; then |
Namhyung Kim | ae0c1f9 | 2012-10-04 14:23:54 +0900 | [diff] [blame] | 23 | _get_comp_words_by_ref -n : cur prev |
Namhyung Kim | a1d668c | 2012-10-03 00:21:32 +0900 | [diff] [blame] | 24 | else |
Namhyung Kim | ae0c1f9 | 2012-10-04 14:23:54 +0900 | [diff] [blame] | 25 | cur=$(_get_cword :) |
Namhyung Kim | a1d668c | 2012-10-03 00:21:32 +0900 | [diff] [blame] | 26 | prev=${COMP_WORDS[COMP_CWORD-1]} |
| 27 | fi |
Frederic Weisbecker | 98a4179 | 2012-08-09 16:31:51 +0200 | [diff] [blame] | 28 | |
| 29 | cmd=${COMP_WORDS[0]} |
| 30 | |
Namhyung Kim | 35c2fde | 2012-10-03 00:21:33 +0900 | [diff] [blame] | 31 | # List perf subcommands or long options |
Frederic Weisbecker | 98a4179 | 2012-08-09 16:31:51 +0200 | [diff] [blame] | 32 | if [ $COMP_CWORD -eq 1 ]; then |
Namhyung Kim | 35c2fde | 2012-10-03 00:21:33 +0900 | [diff] [blame] | 33 | 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 Weisbecker | a3277d2 | 2012-08-09 16:31:52 +0200 | [diff] [blame] | 41 | # List possible events for -e option |
| 42 | elif [[ $prev == "-e" && "${COMP_WORDS[1]}" == @(record|stat|top) ]]; then |
Namhyung Kim | 4d8061f | 2012-10-03 00:21:34 +0900 | [diff] [blame] | 43 | evts=$($cmd list --raw-dump) |
| 44 | COMPREPLY=( $( compgen -W '$evts' -- "$cur" ) ) |
Namhyung Kim | ae0c1f9 | 2012-10-04 14:23:54 +0900 | [diff] [blame] | 45 | __ltrim_colon_completions $cur |
Namhyung Kim | 4d8061f | 2012-10-03 00:21:34 +0900 | [diff] [blame] | 46 | # 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 Weisbecker | 98a4179 | 2012-08-09 16:31:51 +0200 | [diff] [blame] | 51 | fi |
| 52 | } && |
Ramkumar Ramachandra | 7b6c48e | 2013-07-04 18:11:27 +0530 | [diff] [blame] | 53 | |
| 54 | complete -o bashdefault -o default -o nospace -F _perf perf 2>/dev/null \ |
| 55 | || complete -o default -o nospace -F _perf perf |