Skip to content

Instantly share code, notes, and snippets.

@taikedz
Created March 29, 2018 14:33
Show Gist options
  • Save taikedz/b3ea489425c6fb2cf3b771aecfa232d0 to your computer and use it in GitHub Desktop.
Save taikedz/b3ea489425c6fb2cf3b771aecfa232d0 to your computer and use it in GitHub Desktop.
Discover all non-clean git repos under the current directory (modified or untracked files)
#!/bin/bash
set -e
# Rather than use bare binary, use all ASCII
# for web and clipboard compatibility
c_nul="$(echo -e "\033[0m")"
c_red="$(echo -e "\033[31;1m")"
c_yel="$(echo -e "\033[33;1m")"
git-status() { (
cd "$1/.."
echo "${c_yel}$(dirname "$1")${c_nul}"
git status | sed -r "s/^(\t.+)$/${c_red}\1${c_nul}/ ; s/^/\t/"
) ; }
conditional-print() {
if [[ ! "$*" =~ "working tree clean" ]]; then
echo "$*"
fi
}
main() {
if [[ -n "${1:-}" ]]; then
conditional-print "$(git-status "$1")"
else
find . -name '.git' -exec bash "$0" {} \;
fi
}
main "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment