Treat git directories, recursively. Is especially like the fact that I can use it together with git aliases, e.g. I use this at least once a (working) day like `gr -b /path/to/customer/git/repos fap` (--fetch --all --prune).
#!/usr/bin/env bash
set -o errexit
set -o nounset
usage(){
printf "[TRACE=...] %s [-b /path/to/clones/root] (%s/w) -- <git commands/options>\n" "${0##*/}" "$HOME"
}
if [[ -n "${TRACE-}" ]]; then
set -o xtrace
fi
trap 'set +o xtrace' ALRM HUP INT TERM EXIT
: "${GIT_BASE:=$HOME}"
while getopts b:h OPT; do
case "$OPT" in
b) GIT_BASE="$OPTARG";;
h) usage; exit 0;;
*) ;;
esac
done
shift $(( OPTIND - 1 ))
while read -r REPO; do
[[ -d "$REPO"/.git ]] || continue
[[ "$REPO" =~ \.terraform\/modules ]] && continue
tput setaf 8
printf "%s … %s\n" "$REPO" "$( git -C "$REPO" config --local --get remote.origin.url )"
tput sgr0
if [[ $# -eq 0 ]]; then
git -C "$REPO" status -sb
else
git -C "$REPO" "$@"
fi
printf "\n"
done < <( fd --one-file-system --type d . "$GIT_BASE" )