-
-
Save benvd/8470814 to your computer and use it in GitHub Desktop.
ggs: git global status. For a set of repos, display whether they are dirty and/or have unpushed commits.
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 | |
repos=( | |
"/path/to/a/repo" | |
"/path/to/another/repo" | |
) | |
function isClean { | |
# Check for unstaged changes, staged changes, untracked files | |
git diff-files --quiet && git diff-index --quiet --cached HEAD && test -z "$(git ls-files --exclude-standard --others)" | |
} | |
function getNumAhead { | |
# Get the number of unpushed commits on all branches | |
git log --branches --not --remotes --oneline | wc -l | |
} | |
function printRepo { | |
if isClean ; then | |
echo -en "\e[00;32m$1\e[00m" | |
else | |
echo -en "\e[00;31m$1\e[00m" | |
fi | |
numAhead=$(getNumAhead) | |
if [[ $numAhead -eq 0 ]] ; then | |
echo "" | |
else | |
echo -e " \e[00;33m+$numAhead\e[00m" | |
fi | |
} | |
for i in "${repos[@]}"; do | |
pushd $i > /dev/null | |
printRepo `basename $i` | |
popd > /dev/null | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment