Run a git action an all git repositories find below current work directory.
$ git-all status
$ git-all fetch
$ git-all checkout master
$ git-all pull
#!/bin/bash | |
# git-all | |
# | |
# Copyright (c) 2019 Markus Frosch <markus@lazyfrosch.de> | |
# | |
# Licensed under GPL-2+ | |
rc=0 | |
color() { | |
[ -t 1 ] || return | |
for c in "$@" | |
do | |
echo -en "\\e[${c}m" | |
done | |
} | |
echo_reset() { | |
echo -n "$@" | |
[ -t 1 ] && echo -en '\e[0m' | |
echo | |
} | |
GIT_DIRS=() | |
while IFS=$'\n' read -r line | |
do | |
GIT_DIRS+=("$line") | |
done < <(find . -type d -name .git) | |
for git_dir in "${GIT_DIRS[@]}" | |
do | |
dir="$(dirname "$git_dir")" | |
color 97 42 | |
echo_reset "[ $dir - git $* ]" | |
if ! ( cd "$dir" && git "$@" ); then | |
rc=$? | |
fi | |
done | |
exit $rc |