perf completion: Strip function_exists ()
[linux-2.6-block.git] / tools / perf / bash_completion
CommitLineData
98a4179c
FW
1# perf completion
2
4685a6cf 3type __ltrim_colon_completions &>/dev/null ||
ae0c1f99
NK
4__ltrim_colon_completions()
5{
6 if [[ "$1" == *:* && "$COMP_WORDBREAKS" == *:* ]]; then
7 # Remove colon-word prefix from COMPREPLY items
30079d1d 8 local colon_word=${1%"${1##*:}"}
ae0c1f99
NK
9 local i=${#COMPREPLY[*]}
10 while [[ $((--i)) -ge 0 ]]; do
11 COMPREPLY[$i]=${COMPREPLY[$i]#"$colon_word"}
12 done
13 fi
14}
15
1ba6e017 16type perf &>/dev/null &&
98a4179c
FW
17_perf()
18{
a1d668c3 19 local cur prev cmd
98a4179c
FW
20
21 COMPREPLY=()
a1d668c3 22 if function_exists _get_comp_words_by_ref; then
ae0c1f99 23 _get_comp_words_by_ref -n : cur prev
a1d668c3 24 else
ae0c1f99 25 cur=$(_get_cword :)
a1d668c3
NK
26 prev=${COMP_WORDS[COMP_CWORD-1]}
27 fi
98a4179c
FW
28
29 cmd=${COMP_WORDS[0]}
30
35c2fde1 31 # List perf subcommands or long options
98a4179c 32 if [ $COMP_CWORD -eq 1 ]; then
35c2fde1
NK
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
a3277d2d
FW
41 # List possible events for -e option
42 elif [[ $prev == "-e" && "${COMP_WORDS[1]}" == @(record|stat|top) ]]; then
4d8061fa
NK
43 evts=$($cmd list --raw-dump)
44 COMPREPLY=( $( compgen -W '$evts' -- "$cur" ) )
ae0c1f99 45 __ltrim_colon_completions $cur
4d8061fa
NK
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" ) )
98a4179c
FW
51 fi
52} &&
7b6c48e1
RR
53
54complete -o bashdefault -o default -o nospace -F _perf perf 2>/dev/null \
55 || complete -o default -o nospace -F _perf perf