Last active
June 20, 2019 02:49
-
-
Save themattgabriel/c788bf0c4474c2054ed6f1889b5ab530 to your computer and use it in GitHub Desktop.
Find out if each repository in your git folder has modified or untracked files simultaneously
This file contains hidden or 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
#!/usr/bin/env bash | |
# Checks the status of the repos | |
# Use this site for reference regarding Bash colors: https://misc.flogisoft.com/bash/tip_colors_and_formatting | |
# MAKE SURE PATH IS CORRECT | |
CDPATH="CHANGE_TO_PATH" # <--- Put the path to your local repositories here | |
SUCCESS="echo -e \\n\\e[92mgit status check completed\\e[0m\\n" | |
cd "$CDPATH" || return | |
# Find all repositories and find out if each repository has modified or untracked files | |
for i in $(find . -name ".git" | cut -d'/' -f2); do | |
echo "" | |
echo -e "\\e[33m$i\\e[0m" | |
# Switch to the repository | |
cd "$i" || return | |
# Check for modified or untracked files | |
MODIFIED="$(git status | grep modified | sed -n 1p | cut -c 2-9)" | |
UNTRACKED="$(git status | grep Untracked | cut -c -9)" | |
# Check if working tree is clean | |
CLEAN="$(git status | grep clean | cut -c 33-)" | |
if [ "$MODIFIED" = "modified" ] || [ "$UNTRACKED" = "Untracked" ]; then | |
# Modified files | |
if [ "$MODIFIED" = "modified" ]; then | |
echo -e "$NOTICE: \\e[31mModified files detected\\e[0m" | |
elif [ "$MODIFIED" != "modified" ]; then | |
echo "$NOTICE: No modified files detected" | |
fi | |
# Untracked files | |
if [ "$UNTRACKED" = "Untracked" ]; then | |
echo -e "$NOTICE: \\e[31mNew files detected\\e[0m" | |
elif [ "$UNTRACKED" != "Untracked" ]; then | |
echo "$NOTICE: No new files detected" | |
fi | |
elif [ "$CLEAN" = "clean" ]; then | |
echo "Nothing to commit, working tree clean" | |
fi | |
# Return to $CDPATH | |
cd "$CDPATH" || return | |
done | |
echo | |
$SUCCESS | |
exit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment