Skip to content

Instantly share code, notes, and snippets.

@passuf
Forked from mzabriskie/README.md
Last active June 5, 2017 17:54
Show Gist options
  • Save passuf/3fadd69f1fa24ba31410d5c3418fa10a to your computer and use it in GitHub Desktop.
Save passuf/3fadd69f1fa24ba31410d5c3418fa10a to your computer and use it in GitHub Desktop.
Check git status of multiple repos, source: https://gist.github.com/mzabriskie/6631607
#!/bin/bash
dir="$1"
# No directory has been provided, use current
if [ -z "$dir" ]
then
dir="`pwd`"
fi
# Make sure directory ends with "/"
if [[ $dir != */ ]]
then
dir="$dir/*"
else
dir="$dir*"
fi
# Loop all sub-directories
for f in $dir
do
# Only interested in directories
[ -d "${f}" ] || continue
echo -en "\033[0;35m"
echo -n "${f}"
echo -en "\033[0m - "
# Check if directory is a git repository
if [ -d "$f/.git" ]
then
mod=0
cd $f
# Check for modified files
if [ $(git status | grep modified -c) -ne 0 ]
then
mod=1
echo -en "\033[0;31m"
echo -n "Modified files "
echo -en "\033[0m"
fi
# Check for untracked files
if [ $(git status | grep Untracked -c) -ne 0 ]
then
mod=1
echo -en "\033[0;33m"
echo -n "Untracked files "
echo -en "\033[0m"
fi
# Check for unpushed changes
if [ $(git status | grep 'Your branch is ahead' -c) -ne 0 ]
then
mod=1
echo -en "\033[0;32m"
echo -n "Unpushed commit"
echo -en "\033[0m"
fi
# Check if everything is peachy keen
if [ $mod -eq 0 ]
then
echo -n "Nothing to commit"
fi
cd ../
else
echo -n "Not a git repository"
fi
echo
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment