bash-completion 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. # Copyright (c) 2012 The Chromium Authors. All rights reserved.
  2. # Use of this source code is governed by a BSD-style license that can be
  3. # found in the LICENSE file.
  4. # Flag completion rule for bash.
  5. # To load in your shell, "source path/to/this/file".
  6. # Usage examples
  7. # ==============
  8. #
  9. # Browser command line switches:
  10. # $ out/gn/chrome --site-per-pro<tab>
  11. # $ google-chrome --site-per-pro<tab>
  12. #
  13. # Test switches (i.e. --gtest_* and --test-launcher-* switches):
  14. # $ out/gn/unit_tests --gtest_filt<tab>
  15. # $ out/gn/unit_tests --test-launcher-j<tab>
  16. #
  17. # Web test switches:
  18. # $ third_party/blink/tools/run_web_tests.py --additional-driver-f<tab>
  19. # $ .../run_web_tests.py --additional-driver-flag=--site-per-pro<tab>
  20. #
  21. # Blink blink_tool.py sub-commands:
  22. # $ third_party/blink/tools/blink_tool.py reb<tab>
  23. if [ -n "$BASH_SOURCE" ]; then
  24. # The $BASH_SOURCE variable returns path of current script in bash.
  25. chrome_source=$(cd $(dirname $BASH_SOURCE)/.. && pwd)
  26. else
  27. # This is here for other similar shells, e.g. zsh.
  28. chrome_source=$(cd $(dirname $0)/.. && pwd)
  29. fi
  30. _chrome_flag() {
  31. local cur targets
  32. cur="${COMP_WORDS[COMP_CWORD]}"
  33. targets=$(cd $chrome_source; \
  34. git ls-files '*switches*' | \
  35. xargs sed -ne 's/^[^/]*"\([^" /]\{1,\}\)".*/--\1/p')
  36. COMPREPLY=($(compgen -W "$targets" -- "$cur"))
  37. return 0
  38. }
  39. _gtest_flag() {
  40. local cur gtest_flags launcher_flags
  41. cur="${COMP_WORDS[COMP_CWORD]}"
  42. gtest_flags=$(sed -ne 's/^.*FromGTestEnv("\([^" /]\+\)".*$/--gtest_\1/p' \
  43. "$chrome_source/third_party/googletest/src/googletest/src/gtest.cc")
  44. chrome_test_launcher_flags=$(sed -ne 's/^[^/]*"\([^" /]\{1,\}\)".*/--\1/p' \
  45. "$chrome_source/base/test/test_switches.cc")
  46. COMPREPLY=($(
  47. compgen -W "$gtest_flags $chrome_test_launcher_flags" -- "$cur"))
  48. return 0
  49. }
  50. _web_test_flag() {
  51. local cur targets blinkpy_dir prev_switch
  52. cur="${COMP_WORDS[COMP_CWORD]}"
  53. # Complete content_shell switches if appropriate.
  54. if [ "${COMP_CWORD}" -gt 2 -a "${COMP_WORDS[COMP_CWORD-1]}" = "=" ]
  55. then
  56. prev_switch="${COMP_WORDS[COMP_CWORD-2]}"
  57. if [ "$prev_switch" = "--additional-drt-flag" -o \
  58. "$prev_switch" = "--additional-driver-flag" ]
  59. then
  60. targets=$(cd $chrome_source; \
  61. git ls-files 'content/*switches*.cc' | \
  62. xargs sed -ne 's/^[^/]*"\([^" /]\{1,\}\)".*/--\1/p')
  63. COMPREPLY=($(compgen -W "$targets" -- "$cur"))
  64. return 0
  65. fi
  66. fi
  67. # Complete run_web_tests.py switches.
  68. blinkpy_dir="$chrome_source/third_party/blink/tools/blinkpy"
  69. targets=$(sed -ne 's/^[[:space:]]*"\(--[a-z-]\+\)",[[:space:]]*$/\1/p' \
  70. "$blinkpy_dir/web_tests/run_webkit_tests.py")
  71. COMPREPLY=($(compgen -W "$targets" -- "$cur"))
  72. return 0
  73. }
  74. _blink_tool_flag() {
  75. local cur targets blink_tools_dir
  76. cur="${COMP_WORDS[COMP_CWORD]}"
  77. blink_tools_dir=$chrome_source/third_party/blink/tools
  78. targets=$($blink_tools_dir/blink_tool.py help | grep '^ [a-z]' | \
  79. awk '{ print $1 }')
  80. COMPREPLY=($(compgen -W "$targets" -- "$cur"))
  81. return 0
  82. }
  83. complete -F _chrome_flag google-chrome
  84. complete -F _chrome_flag chrome
  85. complete -F _chrome_flag content_shell
  86. if [ $(uname) = "Darwin" ]
  87. then
  88. complete -F _chrome_flag Chromium
  89. fi
  90. for gtest_test_executable in $(
  91. cd $chrome_source;
  92. git ls-files '*/BUILD.gn' | xargs sed -ne 's/^.*test("\([^"]\+\)").*$/\1/p'
  93. ); do
  94. complete -F _gtest_flag $gtest_test_executable
  95. done
  96. complete -F _web_test_flag run_web_tests.py
  97. complete -F _blink_tool_flag blink_tool.py