Last active
August 29, 2015 14:01
-
-
Save skeggse/728c55c2cf39de13b651 to your computer and use it in GitHub Desktop.
Display the statuses of a bunch of git repositories
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
pushd . >> /dev/null | |
top="$(git rev-parse --show-toplevel 2>/dev/null)" | |
if [ "$top" != '' ]; then | |
cd "$(dirname "$top")" | |
fi | |
for dir in * | |
do | |
if [ -d "${dir}" ] && [ -d "${dir}/.git" ]; then | |
pushd . >> /dev/null | |
cd "${dir}" | |
# list of commits that haven't been pushed to their matching remote branches | |
unpushed="$(git rev-list --branches --not --remotes 2>/dev/null)" | |
resp="$(git status --short)" | |
if [ "${resp}" != '' ] || [ "${unpushed}" != '' ]; then | |
printf '\e[1;34m%s\e[m' "${dir}" | |
if [ "${unpushed}" != '' ]; then | |
printf ' \e[1m[\e[1;31m%s\e[m\e[1m]\e[m' "some commits not pushed" | |
fi | |
echo | |
if [ "${resp}" != '' ]; then | |
while read -r file; do | |
if [ "${file:2:1}" == ' ' ]; then | |
mode="${file:0:2}" | |
file="${file:3}" | |
else | |
mode="${file:0:1}" | |
file="${file:2}" | |
fi | |
if [ "${mode// /}" == 'A' ]; then | |
color=32 | |
elif [ "${mode// /}" == 'M' ]; then | |
color=33 | |
elif [ "${mode// /}" == 'D' ]; then | |
color=31 | |
elif [ "${mode}" == '??' ]; then | |
color=36 | |
else | |
color=37 | |
fi | |
printf ' \e[1;%sm%-2s\e[m %s\n' "${color}" "${mode}" "${file}" | |
done < <(echo "${resp}") | |
fi | |
fi | |
popd >> /dev/null | |
fi | |
done | |
popd >> /dev/null |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment