-
-
Save fielding/ccbe5c104adc38a6cc47 to your computer and use it in GitHub Desktop.
script to recursively view the status of multiple 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 | |
# original at https://gist.github.com/c0wfunk/3666392 | |
# revised by Fielding Johnston for personal use | |
# most recent available at | |
# https://gist.github.com/justfielding/f64f7729ae1c0683e3c9 | |
# usage: $0 source_dir [source_dir] ... | |
# where source_dir args are directories containing git repositories | |
red=$(tput setaf 1) | |
green=$(tput setaf 2) | |
yellow=$(tput setaf 3) | |
blue=$(tput setaf 4) | |
purple=$(tput setaf 5) | |
cyan=$(tput setaf 6) | |
reset=$(tput sgr0) | |
cols=$(tput cols) | |
print_center () | |
{ | |
local text="$1" | |
local mid=$(((${#text}+cols)/2)) | |
printf "%*s\n" $mid "$text" | |
} | |
while getopts "vh" o; do | |
case "${o}" in | |
v) | |
verbose=true | |
;; | |
h) | |
# TODO | |
echo "help" | |
exit | |
;; | |
*) | |
# TODO | |
echo "usage:" | |
exit | |
;; | |
esac | |
done | |
shift $(( OPTIND - 1 )) | |
if [ $# -eq 0 ] ; then | |
# TODO | |
echo "usage:" | |
else | |
ARGS=$* | |
fi | |
for i in ${ARGS[*]} ; do | |
print_center "[$i]" | |
find "$i" -name ".git" 2>/dev/null |while read gitdir; do | |
( working=$(dirname "$gitdir") | |
cd "$working" | |
if [ "$verbose" == true ] ; then | |
RES=$(git status | grep -E '^(Changes|Untracked|Your branch|nothing to commit)') | |
else | |
RES=$(git status | grep -E '^(Changes|Untracked|Your branch)') | |
fi | |
STAT="" | |
stat_count=0 | |
grep -e 'Untracked' <<<"${RES}" >/dev/null 2>&1 | |
if [ $? -eq 0 ] ; then | |
STAT="$STAT$purple[Untracked]$reset" | |
((stat_count+=1)) | |
fi | |
grep -e 'Changes not staged for commit' <<<"${RES}" >/dev/null 2>&1 | |
if [ $? -eq 0 ] ; then | |
STAT="$STAT$red[Modified]$reset" | |
((stat_count+=1)) | |
fi | |
grep -e 'Changes to be committed' <<<"${RES}" >/dev/null 2>&1 | |
if [ $? -eq 0 ] ; then | |
STAT="$STAT$green[Staged]$reset" | |
((stat_count+=1)) | |
fi | |
grep -e 'Your branch is ahead' <<<"${RES}" >/dev/null 2>&1 | |
if [ $? -eq 0 ] ; then | |
STAT="$STAT$yellow[Unpushed]$reset" | |
((stat_count+=1)) | |
fi | |
grep -e 'Your branch is behind' <<<"${RES}" >/dev/null 2>&1 | |
if [ $? -eq 0 ] ; then | |
STAT="$STAT$cyan[Unmerged]$reset" | |
((stat_count+=1)) | |
fi | |
grep -e 'nothing to commit, working directory clean' <<<"${RES}" >/dev/null 2>&1 | |
if [ $? -eq 0 ] ; then | |
STAT="$STAT$blue[Clean]$reset" | |
((stat_count+=1)) | |
fi | |
if [ -n "$STAT" ] ; then | |
working=$(echo "$working" | sed -e "s|${i}|.|") | |
printf "%s :%$(( cols-${#working}-2+${#blue}*stat_count+${#reset}*stat_count ))b\n" "$working" "$STAT" | |
fi | |
) | |
done | |
printf "\n" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment