Skip to content

Instantly share code, notes, and snippets.

@aaronblenkush
Forked from c0wfunk/git-multi-status.sh
Last active December 24, 2015 14:59
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 aaronblenkush/6816132 to your computer and use it in GitHub Desktop.
Save aaronblenkush/6816132 to your computer and use it in GitHub Desktop.
#!/bin/bash
# usage: $0 source_dir [source_dir] ...
# where source_dir args are directories containing git repositories
red="\033[00;31m"
green="\033[00;32m"
yellow="\033[00;33m"
blue="\033[00;34m"
purple="\033[00;35m"
cyan="\033[00;36m"
reset="\033[00m"
if [ $# -eq 0 ] ; then
ARGS=( "foldername" "foldername/subfoldername" )
else
ARGS=$@
fi
for i in ${ARGS[@]} ; do
for gitdir in `find $i -name .git -maxdepth 1` ; do
( working=$(dirname $gitdir)
cd $working
RES=$(git status | grep -E '^# (Changes|Untracked|Your branch)')
STAT=""
grep -e 'Untracked' <<<${RES} >/dev/null 2>&1
if [ $? -eq 0 ] ; then
STAT=" $red[Untracked]$reset"
fi
grep -e 'Changes not staged for commit' <<<${RES} >/dev/null 2>&1
if [ $? -eq 0 ] ; then
STAT="$STAT $red[Modified]$reset"
fi
grep -e 'Changes to be committed' <<<${RES} >/dev/null 2>&1
if [ $? -eq 0 ] ; then
STAT="$STAT $green[Staged]$reset"
fi
grep -e 'Your branch is ahead' <<<${RES} >/dev/null 2>&1
if [ $? -eq 0 ] ; then
STAT="$STAT $yellow[Unpushed]$reset"
fi
grep -e 'Your branch is behind' <<<${RES} >/dev/null 2>&1
if [ $? -eq 0 ] ; then
STAT="$STAT $cyan[Unmerged]$reset"
fi
echo -e "$working $STAT"
)
done
done
@aaronblenkush
Copy link
Author

Revised for my own preferences:

  • Limit find to a maxdepth of 1 to prevent unnecessary recursion through massive repos
  • Echo the paths for each repo, not just "dirty" repos

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment