diff options
author | Damien Martin-Guillerez <dmarting@google.com> | 2016-08-23 11:21:21 +0000 |
---|---|---|
committer | John Cater <jcater@google.com> | 2016-08-23 22:57:08 +0000 |
commit | ae537ce9e275dd6d006f7b611025d9452895849f (patch) | |
tree | 8416e4db5cddb5eb34f56e93ef11d2bb8735b672 /scripts/bazel-complete-template.bash | |
parent | 141b6c2a48353a0a4e2c0debe8f040adb41ab349 (diff) |
Use path given by which to invoke grep to bypass aliases set by the user
If the user had an alias grep='grep --color=always' it would break the
bash completion, outputting the formatting character. Bypass the user
alias to avoid the effect.
--
MOS_MIGRATED_REVID=131040601
Diffstat (limited to 'scripts/bazel-complete-template.bash')
-rw-r--r-- | scripts/bazel-complete-template.bash | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/scripts/bazel-complete-template.bash b/scripts/bazel-complete-template.bash index 9c138132b5..e6f87a6353 100644 --- a/scripts/bazel-complete-template.bash +++ b/scripts/bazel-complete-template.bash @@ -75,6 +75,8 @@ : ${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() { @@ -187,7 +189,7 @@ _bazel__matching_targets() { | sed 's/\([a-zA-Z0-9_]*\) *(\([^)]* \)\{0,1\}name *= *['\''"]\([a-zA-Z0-9_/.+=,@~-]*\)['\''"][^)]*)/\ type:\1 name:\3\ /g' \ - | grep -E "^type:$kind_pattern name:$target_prefix" \ + | "${BAZEL_GREP}" -E "^type:$kind_pattern name:$target_prefix" \ | cut -d ':' -f 3 } @@ -226,7 +228,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: | grep "^$rule_prefix") + cut -f2 -d: | "${BAZEL_GREP}" "^$rule_prefix") else for root in $(_bazel__package_path "$workspace" "$displacement"); do buildfile="$root/$package_name/BUILD" @@ -317,7 +319,7 @@ _bazel__expand_target_pattern() { _bazel__get_command() { for word in "${COMP_WORDS[@]:1:COMP_CWORD-1}"; do - if echo "$BAZEL_COMMAND_LIST" | grep -wsq -e "$word"; then + if echo "$BAZEL_COMMAND_LIST" | "${BAZEL_GREP}" -wsq -e "$word"; then echo $word break fi @@ -357,7 +359,7 @@ _bazel__complete_pattern() { ;; "command") local commands=$(echo "${BAZEL_COMMAND_LIST}" \ - | tr " " "\n" | grep -v "^${BAZEL_IGNORED_COMMAND_REGEX}$") + | tr " " "\n" | "${BAZEL_GREP}" -v "^${BAZEL_IGNORED_COMMAND_REGEX}$") compgen -S " " -W "${commands}" -- "$current" ;; path) @@ -402,7 +404,7 @@ _bazel__complete_stdout() { case "$command" in "") # Expand startup-options or commands local commands=$(echo "${BAZEL_COMMAND_LIST}" \ - | tr " " "\n" | grep -v "^${BAZEL_IGNORED_COMMAND_REGEX}$") + | tr " " "\n" | "${BAZEL_GREP}" -v "^${BAZEL_IGNORED_COMMAND_REGEX}$") _bazel__expand_options "$workspace" "$displacement" "$cur" \ "${commands}\ ${BAZEL_STARTUP_OPTIONS}" |