I have this code to check the status of all of my git folders.
find / -maxdepth 3 -not -path / -path '/[[:upper:]]*' -type d -name .git -not -path "*/Trash/*" -not -path "*/Temp/*" -not -path "*/opt/*" -print 2>/dev/null |
{
while read gitFolder; do
(
parent=$(dirname $gitFolder);
Status=$(git -C $parent status)
if [[ $Status == *Changes* ]]; then
echo $parent;
git -C $parent status --porcelain
echo ""
elif [[ $Status == *ahead* ]]; then
echo "Push $parent";
echo
elif [[ $Status == *diverged* ]]; then
echo "Sync $parent";
echo
fi
) &
done
wait
}
When I run it sequentially, I get a nice readable print in the terminal. But the speed gets slower. When I run it in parallel (using &
), I get a very good speed, but the output becomes a total mess.
Is it possible to lock the output for each inner shell somehow and print each inner shell's standard output in a block?
Info "Push $parent"; Divide