Last active
November 18, 2021 16:06
-
-
Save SimonGoring/e024d857fbb406ed8cf37ae9b54c0d51 to your computer and use it in GitHub Desktop.
A short bash script to check a directory and report whether Git projects have been committed, or are being tracked.
This file contains 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
#!/bin/bash | |
curdir=$PWD | |
RED='\033[1;31m' | |
YELLOW='\033[1;33m' | |
GREEN='\033[1;32m' | |
NC='\033[0m' # No Color | |
cnt=0 | |
good=0 | |
untr=0 | |
uncom=0 | |
for D in */; do | |
cnt=$((cnt+1)) | |
cd $D | |
find -maxdepth 1 -name '\.git' -type d -print -quit | grep '\.git' &> /dev/null | |
if [ $? == 0 ]; then | |
if [ -z "$(git status --porcelain)" ]; then | |
good=$((good+1)) | |
printf "${GREEN}%-30s${NC} is tracked and up to date.\n" $D | |
else | |
printf "${RED}%-30s${NC} contains untracked (or uncommitted) files.\n" $D | |
uncom=$((uncom+1)) | |
fi | |
else | |
printf "${YELLOW}%-30s${NC} is not currently tracked with git.\n" $D | |
untr=$((untr+1)) | |
fi | |
cd $curdir | |
done | |
printf "You currently have:\n * %s clean project folders\n * %s tracked folders awaiting commits\n * %s untracked folders\n" $good $uncom $untr |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment