3 ms·
→ cat ~/bin/git-all #!/bin/bash # Exit on error. Append "|| true" if you expect an error. set -o errexit # Exit on error inside any functions o
by joshka 8y ago
→ cat ~/bin/git-all
#!/bin/bash
# Exit on error. Append "|| true" if you expect an error.
set -o errexit
# Exit on error inside any functions or subshells.
set -o errtrace
# Do not allow use of undefined vars. Use ${VAR:-} to use an undefined VAR
set -o nounset
# Catch the error in case command1 fails (but command2 succeeds) in `command1 |command2`
set -o pipefail
# Turn on traces, useful while debugging but commented out by default
# set -o xtrace
help() {
cat <<EOF
usage: git all <any-git-command>
Runs the git command for all repositories in the current directory.
Examples:
What just happened?
git all log -1 --oneline
What am I doing now?
git all status --short --branch
What is everything I'm working on?
git all branch -vv
EOF
}
banner() {
echo -e "\\033[1m=== $1 ===\\033[0m"
}
main() {
if (( $# < 1 )); then
help
exit 1
fi
folders=$(find . -maxdepth 2 -name .git -print0 | xargs -0 -n1 dirname)
for folder in $folders;
do
banner "$folder"
git -C "$folder" "$@" || true
done
}
main "$@"
- stinos 8y agoMissed this reply, but yes, that's what I'm talking about!