1 # Copyright 2012 The Chromium Authors
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
5 # Flag completion rule for bash.
6 # To load in your shell, "source path/to/this/file".
11 # Browser command line switches:
12 # $ out/gn/chrome --site-per-pro<tab>
13 # $ google-chrome --site-per-pro<tab>
15 # Test switches (i.e. --gtest_* and --test-launcher-* switches):
16 # $ out/gn/unit_tests --gtest_filt<tab>
17 # $ out/gn/unit_tests --test-launcher-j<tab>
20 # $ third_party/blink/tools/run_web_tests.py --additional-driver-f<tab>
21 # $ .../run_web_tests.py --additional-driver-flag=--site-per-pro<tab>
23 # Blink blink_tool.py sub-commands:
24 # $ third_party/blink/tools/blink_tool.py reb<tab>
26 if [ -n "$BASH_SOURCE" ]; then
27 # The $BASH_SOURCE variable returns path of current script in bash.
28 chrome_source=$(cd $(dirname $BASH_SOURCE)/.. && pwd)
30 # This is here for other similar shells, e.g. zsh.
31 chrome_source=$(cd $(dirname $0)/.. && pwd)
36 cur="${COMP_WORDS[COMP_CWORD]}"
37 targets=$(cd $chrome_source; \
38 git ls-files '*switches*' | \
39 xargs sed -ne 's/^[^/]*"\([^" /]\{1,\}\)".*/--\1/p')
40 COMPREPLY=($(compgen -W "$targets" -- "$cur"))
45 local cur gtest_flags launcher_flags
46 cur="${COMP_WORDS[COMP_CWORD]}"
47 gtest_flags=$(sed -ne 's/^.*FromGTestEnv("\([^" /]\+\)".*$/--gtest_\1/p' \
48 "$chrome_source/third_party/googletest/src/googletest/src/gtest.cc")
49 chrome_test_launcher_flags=$(sed -ne 's/^[^/]*"\([^" /]\{1,\}\)".*/--\1/p' \
50 "$chrome_source/base/test/test_switches.cc")
52 compgen -W "$gtest_flags $chrome_test_launcher_flags" -- "$cur"))
57 local cur targets blinkpy_dir prev_switch
58 cur="${COMP_WORDS[COMP_CWORD]}"
60 # Complete content_shell switches if appropriate.
61 if [ "${COMP_CWORD}" -gt 2 -a "${COMP_WORDS[COMP_CWORD-1]}" = "=" ]
63 prev_switch="${COMP_WORDS[COMP_CWORD-2]}"
64 if [ "$prev_switch" = "--additional-drt-flag" -o \
65 "$prev_switch" = "--additional-driver-flag" ]
67 targets=$(cd $chrome_source; \
68 git ls-files 'content/*switches*.cc' | \
69 xargs sed -ne 's/^[^/]*"\([^" /]\{1,\}\)".*/--\1/p')
70 COMPREPLY=($(compgen -W "$targets" -- "$cur"))
75 # Complete run_web_tests.py switches.
76 blinkpy_dir="$chrome_source/third_party/blink/tools/blinkpy"
77 targets=$(sed -ne 's/^[[:space:]]*"\(--[a-z-]\+\)",[[:space:]]*$/\1/p' \
78 "$blinkpy_dir/web_tests/run_webkit_tests.py")
79 COMPREPLY=($(compgen -W "$targets" -- "$cur"))
84 local cur targets blink_tools_dir
85 cur="${COMP_WORDS[COMP_CWORD]}"
86 blink_tools_dir=$chrome_source/third_party/blink/tools
87 targets=$($blink_tools_dir/blink_tool.py help | grep '^ [a-z]' | \
89 COMPREPLY=($(compgen -W "$targets" -- "$cur"))
93 complete -F _chrome_flag google-chrome
94 complete -F _chrome_flag chrome
95 complete -F _chrome_flag content_shell
96 if [ $(uname) = "Darwin" ]
98 complete -F _chrome_flag Chromium
101 for gtest_test_executable in $(
103 git ls-files '*/BUILD.gn' | xargs sed -ne 's/^.*test("\([^"]\+\)").*$/\1/p'
105 complete -F _gtest_flag $gtest_test_executable
108 complete -F _web_test_flag run_web_tests.py
109 complete -F _blink_tool_flag blink_tool.py