From 86a40472a490e8cc8b1793db17b012b0fc21cd23 Mon Sep 17 00:00:00 2001 From: Googler Date: Tue, 6 Sep 2016 18:01:11 +0000 Subject: 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 --- scripts/bazel-complete-template.bash | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'scripts/bazel-complete-template.bash') 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 # 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}" -- cgit v1.2.3