summaryrefslogtreecommitdiff
path: root/chromium/tools/bash-completion
blob: 2c5c00f558654fea43add12a7aba966f9077ade8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# Copyright (c) 2012 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

# Flag completion rule for bash.
# To load in your shell, "source path/to/this/file".

# Usage examples
# ==============
#
# Browser command line switches:
# $ out/gn/chrome --site-per-pro<tab>
# $ google-chrome --site-per-pro<tab>
#
# Test switches (i.e. --gtest_* and --test-launcher-* switches):
# $ out/gn/unit_tests --gtest_filt<tab>
# $ out/gn/unit_tests --test-launcher-j<tab>
#
# Layout test switches:
# $ third_party/WebKit/Tools/Scripts/run-webkit-tests --additional-driver-f<tab>
# $ .../run-webkit-tests --additional-driver-flag=--site-per-pro<tab>
#
# Blink webkit-patch sub-commands:
# $ third_party/WebKit/Tools/Scripts/webkit-patch reb<tab>

if [ -n "$BASH_SOURCE" ]; then
    # The $BASH_SOURCE variable returns path of current script in bash.
    chrome_source=$(cd $(dirname $BASH_SOURCE)/.. && pwd)
else
    # This is here for other similar shells, e.g. zsh.
    chrome_source=$(cd $(dirname $0)/.. && pwd)
fi

_chrome_flag() {
    local cur targets
    cur="${COMP_WORDS[COMP_CWORD]}"
    targets=$(cd $chrome_source; \
        git ls-files '*switches*' | \
        xargs sed -ne 's/^[^/]*"\([^" /]\{1,\}\)".*/--\1/p')
    COMPREPLY=($(compgen -W "$targets" -- "$cur"))
    return 0
}

_gtest_flag() {
    local cur gtest_flags launcher_flags
    cur="${COMP_WORDS[COMP_CWORD]}"
    gtest_flags=$(sed -ne 's/^.*FromGTestEnv("\([^" /]\+\)".*$/--gtest_\1/p' \
      "$chrome_source/testing/gtest/src/gtest.cc")
    chrome_test_launcher_flags=$(sed -ne 's/^[^/]*"\([^" /]\{1,\}\)".*/--\1/p' \
      "$chrome_source/base/test/test_switches.cc")
    COMPREPLY=($(
      compgen -W "$gtest_flags $chrome_test_launcher_flags" -- "$cur"))
    return 0
}

_layout_test_flag() {
    local cur targets webkitpy_dir prev_switch
    cur="${COMP_WORDS[COMP_CWORD]}"

    # Complete content_shell switches if appropriate.
    if [ "${COMP_CWORD}" -gt 2 -a "${COMP_WORDS[COMP_CWORD-1]}" = "=" ]
    then
      prev_switch="${COMP_WORDS[COMP_CWORD-2]}"
      if [ "$prev_switch" = "--additional-drt-flag" -o \
           "$prev_switch" = "--additional-driver-flag" ]
      then
        targets=$(cd $chrome_source; \
            git ls-files 'content/*switches*.cc' | \
            xargs sed -ne 's/^[^/]*"\([^" /]\{1,\}\)".*/--\1/p')
        COMPREPLY=($(compgen -W "$targets" -- "$cur"))
        return 0
      fi
    fi

    # Complete run-webkit-tests switches.
    webkitpy_dir="$chrome_source/third_party/WebKit/Tools/Scripts/webkitpy"
    targets=$(sed -ne 's/^[[:space:]]*"\(--[a-z-]\+\)",[[:space:]]*$/\1/p' \
        "$webkitpy_dir/layout_tests/run_webkit_tests.py")
    COMPREPLY=($(compgen -W "$targets" -- "$cur"))
    return 0
}

_webkit_patch_flag() {
    local cur targets webkit_scripts_dir
    cur="${COMP_WORDS[COMP_CWORD]}"
    webkit_scripts_dir=$chrome_source/third_party/WebKit/Tools/Scripts
    targets=$($webkit_scripts_dir/webkit-patch help | grep '^   [a-z]' | \
        awk '{ print $1 }')
    COMPREPLY=($(compgen -W "$targets" -- "$cur"))
    return 0
}

complete -F _chrome_flag google-chrome
complete -F _chrome_flag chrome
if [ $(uname) = "Darwin" ]
then
  complete -F _chrome_flag Chromium
fi

for gtest_test_executable in $(
  cd $chrome_source;
  git ls-files '*/BUILD.gn' | xargs sed -ne 's/^.*test("\([^"]\+\)").*$/\1/p'
); do
  complete -F _gtest_flag $gtest_test_executable
done

complete -F _layout_test_flag run-webkit-tests
complete -F _webkit_patch_flag webkit-patch