Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/sparc
[deliverable/linux.git] / tools / perf / bash_completion
CommitLineData
98a4179c
FW
1# perf completion
2
a1d668c3
NK
3function_exists()
4{
5 declare -F $1 > /dev/null
6 return $?
7}
8
ae0c1f99
NK
9function_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
98a4179c
FW
22have perf &&
23_perf()
24{
a1d668c3 25 local cur prev cmd
98a4179c
FW
26
27 COMPREPLY=()
a1d668c3 28 if function_exists _get_comp_words_by_ref; then
ae0c1f99 29 _get_comp_words_by_ref -n : cur prev
a1d668c3 30 else
ae0c1f99 31 cur=$(_get_cword :)
a1d668c3
NK
32 prev=${COMP_WORDS[COMP_CWORD-1]}
33 fi
98a4179c
FW
34
35 cmd=${COMP_WORDS[0]}
36
35c2fde1 37 # List perf subcommands or long options
98a4179c 38 if [ $COMP_CWORD -eq 1 ]; then
35c2fde1
NK
39 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
a3277d2d
FW
47 # List possible events for -e option
48 elif [[ $prev == "-e" && "${COMP_WORDS[1]}" == @(record|stat|top) ]]; then
4d8061fa
NK
49 evts=$($cmd list --raw-dump)
50 COMPREPLY=( $( compgen -W '$evts' -- "$cur" ) )
ae0c1f99 51 __ltrim_colon_completions $cur
4d8061fa
NK
52 # 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" ) )
98a4179c
FW
57 # Fall down to list regular files
58 else
59 _filedir
60 fi
61} &&
62complete -F _perf perf
This page took 0.061085 seconds and 5 git commands to generate.