#!/bin/sh set -eu COLOUR=auto case "${1:-}" in --color=auto|--colour=auto) shift ;; --color=yes|--colour=yes|--color|--colour) COLOUR=true; shift ;; --color=no|--colour=no) COLOUR=false; shift ;; esac if [ "$COLOUR" = auto -a -t 1 ]; then COLOUR=true elif [ "$COLOUR" != true ]; then COLOUR=false fi if $COLOUR; then COLOUR="$(printf '\x1b[32m')" NORMAL="$(printf '\x1b[39;49m')" else COLOUR= NORMAL= fi while [ "$PWD" != / -a ! -s "$PWD/.repo/manifest.xml" ]; do cd .. done if [ ! -s "$PWD/.repo/manifest.xml" ]; then echo "not in a repo tree" >&2 exit 1 fi GIT="`which git`" git() { local dir="$1" shift "$GIT" --git-dir "$dir/.git" --work-tree "$dir" "$@" } case "${0##*/}" in repo-grep) if [ $# -gt 0 ]; then repo list -p | while read p; do git "$p" grep ${COLOUR:+--color=always} "$@" | sed -e "s|^|$COLOUR$p$NORMAL/|" done fi ;; repo-find|*) repo list -p | while read p; do if [ $# -gt 0 ]; then git "$p" ls-files | grep "$@" else git "$p" ls-files fi | sed -e "s|^|$COLOUR$p$NORMAL/|" done ;; esac