Skip to content

Instantly share code, notes, and snippets.

@jeremywrnr
Last active February 11, 2016 18:28
Show Gist options
  • Save jeremywrnr/e375a98b22263c17e07d to your computer and use it in GitHub Desktop.
Save jeremywrnr/e375a98b22263c17e07d to your computer and use it in GitHub Desktop.
Use find and sed to show status of all git repos (under cwd)
#!/bin/bash
# status - a git tool by jeremy warner
# cycle through subfolders, run git status, cleanup
# check if verbose
for arg; do if [[ $arg == "-v" ]]; then verbose="true"; fi; done
function git-stat # loop over folders, run git status
{
find . -type d -name ".git"\
-exec dirname {} \;\
-exec git --git-dir={} --work-tree="$PWD"/{}/.. status \;\
-exec printf "\n" \;
}
# sed terminal colors
RESET=`echo -e "\033[0;0m"`
GREEN=`echo -e "\033[0;32m"`
PURPL=`echo -e "\033[0;35m"`
CYAN=`echo -e "\033[0;36m"`
UCYAN=`echo -e "\033[4;36m"`
function git-parser # parsing pipeline, clean n color output
{
sed -n -e "
/^\.\//{
# print out the current repo
s_^\.\/\(.*\)_$CYAN\[\1\]${RESET}_
N
# mute git repo error
/fatal: Not a git repository/{
d
b
}
N
# print branch if not master
/master/!{
s_\(.*\)\nOn branch \(.*\)_\1\ on \2_
}
/master/{
s_\(.*\)\nOn branch master_\1_
}
s_\(.*\)\nYour branch is up-to-date with .*_$GREEN\[ok\]$RESET\1_
N
# filter out saying repo is clean if it is
s_\(.*\)\nnothing to commit, working directory clean.*_\1_
}
# print anything, if we have it
/./p
"
}
# loop over all folders, run git status
printf "Starting in $UCYAN$PWD...$RESET\n\n"
if [[ $verbose == "true" ]]; then
git-stat
else
git-stat | git-parser
fi
# cleanup format
printf "\n$RESET"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment