bash_completion 937 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. # perf completion
  2. function_exists()
  3. {
  4. declare -F $1 > /dev/null
  5. return $?
  6. }
  7. have perf &&
  8. _perf()
  9. {
  10. local cur prev cmd
  11. COMPREPLY=()
  12. if function_exists _get_comp_words_by_ref; then
  13. _get_comp_words_by_ref cur prev
  14. else
  15. cur=$(_get_cword)
  16. prev=${COMP_WORDS[COMP_CWORD-1]}
  17. fi
  18. cmd=${COMP_WORDS[0]}
  19. # List perf subcommands or long options
  20. if [ $COMP_CWORD -eq 1 ]; then
  21. if [[ $cur == --* ]]; then
  22. COMPREPLY=( $( compgen -W '--help --version \
  23. --exec-path --html-path --paginate --no-pager \
  24. --perf-dir --work-tree --debugfs-dir' -- "$cur" ) )
  25. else
  26. cmds=$($cmd --list-cmds)
  27. COMPREPLY=( $( compgen -W '$cmds' -- "$cur" ) )
  28. fi
  29. # List possible events for -e option
  30. elif [[ $prev == "-e" && "${COMP_WORDS[1]}" == @(record|stat|top) ]]; then
  31. cmds=$($cmd list --raw-dump)
  32. COMPREPLY=( $( compgen -W '$cmds' -- "$cur" ) )
  33. # Fall down to list regular files
  34. else
  35. _filedir
  36. fi
  37. } &&
  38. complete -F _perf perf