bash_completion 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. # perf completion
  2. function_exists()
  3. {
  4. declare -F $1 > /dev/null
  5. return $?
  6. }
  7. function_exists __ltrim_colon_completions ||
  8. __ltrim_colon_completions()
  9. {
  10. if [[ "$1" == *:* && "$COMP_WORDBREAKS" == *:* ]]; then
  11. # Remove colon-word prefix from COMPREPLY items
  12. local colon_word=${1%${1##*:}}
  13. local i=${#COMPREPLY[*]}
  14. while [[ $((--i)) -ge 0 ]]; do
  15. COMPREPLY[$i]=${COMPREPLY[$i]#"$colon_word"}
  16. done
  17. fi
  18. }
  19. have perf &&
  20. _perf()
  21. {
  22. local cur prev cmd
  23. COMPREPLY=()
  24. if function_exists _get_comp_words_by_ref; then
  25. _get_comp_words_by_ref -n : cur prev
  26. else
  27. cur=$(_get_cword :)
  28. prev=${COMP_WORDS[COMP_CWORD-1]}
  29. fi
  30. cmd=${COMP_WORDS[0]}
  31. # List perf subcommands or long options
  32. if [ $COMP_CWORD -eq 1 ]; then
  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
  41. # List possible events for -e option
  42. elif [[ $prev == "-e" && "${COMP_WORDS[1]}" == @(record|stat|top) ]]; then
  43. evts=$($cmd list --raw-dump)
  44. COMPREPLY=( $( compgen -W '$evts' -- "$cur" ) )
  45. __ltrim_colon_completions $cur
  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" ) )
  51. # Fall down to list regular files
  52. else
  53. _filedir
  54. fi
  55. } &&
  56. complete -F _perf perf