blob: e86767f17026d9ada6dda7741b0509165ed97ad2 [file] [log] [blame]
[email protected]37e2a8082012-02-03 21:44:541# 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
5# Flag completion rule for bash.
6# To load in your shell, "source path/to/this/file".
7
lukaszaca7fac622016-10-26 18:59:228# Usage examples
9# ==============
10#
11# Browser command line switches:
12# $ out/gn/chrome --site-per-pro<tab>
13# $ google-chrome --site-per-pro<tab>
14#
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>
18#
19# Layout test switches:
20# $ third_party/WebKit/Tools/Scripts/run-webkit-tests --additional-driver-f<tab>
21# $ .../run-webkit-tests --additional-driver-flag=--site-per-pro<tab>
22
[email protected]19f30442012-02-22 01:47:4423chrome_source=$(cd $(dirname $BASH_SOURCE)/.. && pwd)
[email protected]37e2a8082012-02-03 21:44:5424
25_chrome_flag() {
26 local cur targets
27 cur="${COMP_WORDS[COMP_CWORD]}"
28 targets=$(cd $chrome_source; \
[email protected]4f1594d2012-02-03 23:37:2129 git ls-files '*switches*' | \
[email protected]19f30442012-02-22 01:47:4430 xargs sed -ne 's/^[^/]*"\([^" /]\{1,\}\)".*/--\1/p')
[email protected]37e2a8082012-02-03 21:44:5431 COMPREPLY=($(compgen -W "$targets" -- "$cur"))
32 return 0
33}
34
lukaszab2789fb2016-10-19 23:59:5035_gtest_flag() {
36 local cur gtest_flags launcher_flags
37 cur="${COMP_WORDS[COMP_CWORD]}"
38 gtest_flags=$(sed -ne 's/^.*FromGTestEnv("\([^" /]\+\)".*$/--gtest_\1/p' \
39 "$chrome_source/testing/gtest/src/gtest.cc")
40 chrome_test_launcher_flags=$(sed -ne 's/^[^/]*"\([^" /]\{1,\}\)".*/--\1/p' \
41 "$chrome_source/base/test/test_switches.cc")
42 COMPREPLY=($(
43 compgen -W "$gtest_flags $chrome_test_launcher_flags" -- "$cur"))
44 return 0
45}
46
lukaszaca7fac622016-10-26 18:59:2247_layout_test_flag() {
48 local cur targets webkitpy_dir prev_switch
49 cur="${COMP_WORDS[COMP_CWORD]}"
50
51 # Complete content_shell switches if appropriate.
52 if [ "${COMP_CWORD}" -gt 2 -a "${COMP_WORDS[COMP_CWORD-1]}" = "=" ]
53 then
54 prev_switch="${COMP_WORDS[COMP_CWORD-2]}"
55 if [ "$prev_switch" = "--additional-drt-flag" -o \
56 "$prev_switch" = "--additional-driver-flag" ]
57 then
58 targets=$(cd $chrome_source; \
59 git ls-files 'content/*switches*.cc' | \
60 xargs sed -ne 's/^[^/]*"\([^" /]\{1,\}\)".*/--\1/p')
61 COMPREPLY=($(compgen -W "$targets" -- "$cur"))
62 return 0
63 fi
64 fi
65
66 # Complete run-webkit-tests switches.
67 webkitpy_dir="$chrome_source/third_party/WebKit/Tools/Scripts/webkitpy"
68 targets=$(sed -ne 's/^[[:space:]]*"\(--[a-z-]\+\)",[[:space:]]*$/\1/p' \
69 "$webkitpy_dir/layout_tests/run_webkit_tests.py")
70 COMPREPLY=($(compgen -W "$targets" -- "$cur"))
71 return 0
72}
73
[email protected]37e2a8082012-02-03 21:44:5474complete -F _chrome_flag google-chrome
75complete -F _chrome_flag chrome
[email protected]19f30442012-02-22 01:47:4476if [ $(uname) = "Darwin" ]
77then
78 complete -F _chrome_flag Chromium
79fi
lukaszab2789fb2016-10-19 23:59:5080
81for gtest_test_executable in $(
82 cd $chrome_source;
83 git ls-files '*/BUILD.gn' | xargs sed -ne 's/^test("\([^"]\+\)").*$/\1/p'
84); do
85 complete -F _gtest_flag $gtest_test_executable
86done
lukaszaca7fac622016-10-26 18:59:2287
88complete -F _layout_test_flag run-webkit-tests