You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
1.0 KiB

  1. #!/bin/sh
  2. set -eu
  3. COLOUR=auto
  4. case "${1:-}" in
  5. --color=auto|--colour=auto) shift ;;
  6. --color=yes|--colour=yes|--color|--colour) COLOUR=true; shift ;;
  7. --color=no|--colour=no) COLOUR=false; shift ;;
  8. esac
  9. if [ "$COLOUR" = auto -a -t 1 ]; then
  10. COLOUR=true
  11. elif [ "$COLOUR" != true ]; then
  12. COLOUR=false
  13. fi
  14. if $COLOUR; then
  15. COLOUR="$(printf '\x1b[32m')"
  16. NORMAL="$(printf '\x1b[39;49m')"
  17. else
  18. COLOUR=
  19. NORMAL=
  20. fi
  21. while [ "$PWD" != / -a ! -s "$PWD/.repo/manifest.xml" ]; do
  22. cd ..
  23. done
  24. if [ ! -s "$PWD/.repo/manifest.xml" ]; then
  25. echo "not in a repo tree" >&2
  26. exit 1
  27. fi
  28. GIT="`which git`"
  29. git() {
  30. local dir="$1"
  31. shift
  32. "$GIT" --git-dir "$dir/.git" --work-tree "$dir" "$@"
  33. }
  34. case "${0##*/}" in
  35. repo-grep)
  36. if [ $# -gt 0 ]; then
  37. repo list -p | while read p; do
  38. git "$p" grep ${COLOUR:+--color=always} "$@" | sed -e "s|^|$COLOUR$p$NORMAL/|"
  39. done
  40. fi
  41. ;;
  42. repo-find|*)
  43. repo list -p | while read p; do
  44. if [ $# -gt 0 ]; then
  45. git "$p" ls-files | grep "$@"
  46. else
  47. git "$p" ls-files
  48. fi | sed -e "s|^|$COLOUR$p$NORMAL/|"
  49. done
  50. ;;
  51. esac