Skip to content

Instantly share code, notes, and snippets.

@skeggse
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skeggse/728c55c2cf39de13b651 to your computer and use it in GitHub Desktop.
Save skeggse/728c55c2cf39de13b651 to your computer and use it in GitHub Desktop.
Display the statuses of a bunch of git repositories
#!/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