aboutsummaryrefslogtreecommitdiffhomepage
path: root/scripts/bazel-complete-template.bash
diff options
context:
space:
mode:
authorGravatar Googler <noreply@google.com>2016-09-06 18:01:11 +0000
committerGravatar Yue Gan <yueg@google.com>2016-09-07 10:34:22 +0000
commit86a40472a490e8cc8b1793db17b012b0fc21cd23 (patch)
tree44757dfd9815c4bba2dd3b576aee00076b67846c /scripts/bazel-complete-template.bash
parent900202fe4418490abca96afd7ebf2b92268be244 (diff)
Properly avoid aliases when invoking grep. Using $(which grep) instead of plain grep does not avoid alias interference, it merely trades problems when "grep" is an alias for problems when "which" is an alias (both are commonly defined as aliases).
A more reliable way to turn off alias expansion is to simply quote the command name, which is what I'm doing here. -- MOS_MIGRATED_REVID=132338563
Diffstat (limited to 'scripts/bazel-complete-template.bash')
-rw-r--r--scripts/bazel-complete-template.bash12
1 files changed, 5 insertions, 7 deletions
diff --git a/scripts/bazel-complete-template.bash b/scripts/bazel-complete-template.bash
index e6f87a6353..725a03f28c 100644
--- a/scripts/bazel-complete-template.bash
+++ b/scripts/bazel-complete-template.bash
@@ -75,8 +75,6 @@
: ${BAZEL_BUILD_MATCH_PATTERN__:='.*'}
: ${BAZEL_QUERY_MATCH_PATTERN__:=''}
-BAZEL_GREP="$(which grep)"
-
# Usage: _bazel__get_rule_match_pattern <command>
# Determine what kind of rules to match, based on command.
_bazel__get_rule_match_pattern() {
@@ -189,7 +187,7 @@ _bazel__matching_targets() {
| sed 's/\([a-zA-Z0-9_]*\) *(\([^)]* \)\{0,1\}name *= *['\''"]\([a-zA-Z0-9_/.+=,@~-]*\)['\''"][^)]*)/\
type:\1 name:\3\
/g' \
- | "${BAZEL_GREP}" -E "^type:$kind_pattern name:$target_prefix" \
+ | "grep" -E "^type:$kind_pattern name:$target_prefix" \
| cut -d ':' -f 3
}
@@ -228,7 +226,7 @@ _bazel__expand_rules_in_package() {
result=$(${BAZEL} --output_base=/tmp/${BAZEL}-completion-$USER query \
--keep_going --noshow_progress \
"kind('$pattern rule', '$package_name:*')" 2>/dev/null |
- cut -f2 -d: | "${BAZEL_GREP}" "^$rule_prefix")
+ cut -f2 -d: | "grep" "^$rule_prefix")
else
for root in $(_bazel__package_path "$workspace" "$displacement"); do
buildfile="$root/$package_name/BUILD"
@@ -319,7 +317,7 @@ _bazel__expand_target_pattern() {
_bazel__get_command() {
for word in "${COMP_WORDS[@]:1:COMP_CWORD-1}"; do
- if echo "$BAZEL_COMMAND_LIST" | "${BAZEL_GREP}" -wsq -e "$word"; then
+ if echo "$BAZEL_COMMAND_LIST" | "grep" -wsq -e "$word"; then
echo $word
break
fi
@@ -359,7 +357,7 @@ _bazel__complete_pattern() {
;;
"command")
local commands=$(echo "${BAZEL_COMMAND_LIST}" \
- | tr " " "\n" | "${BAZEL_GREP}" -v "^${BAZEL_IGNORED_COMMAND_REGEX}$")
+ | tr " " "\n" | "grep" -v "^${BAZEL_IGNORED_COMMAND_REGEX}$")
compgen -S " " -W "${commands}" -- "$current"
;;
path)
@@ -404,7 +402,7 @@ _bazel__complete_stdout() {
case "$command" in
"") # Expand startup-options or commands
local commands=$(echo "${BAZEL_COMMAND_LIST}" \
- | tr " " "\n" | "${BAZEL_GREP}" -v "^${BAZEL_IGNORED_COMMAND_REGEX}$")
+ | tr " " "\n" | "grep" -v "^${BAZEL_IGNORED_COMMAND_REGEX}$")
_bazel__expand_options "$workspace" "$displacement" "$cur" \
"${commands}\
${BAZEL_STARTUP_OPTIONS}"