Using Hazel to Highlight any Uncommitted git Changes

Today I thought I’d share one of the more esoteric Hazel rules I use to monitor the files on my Mac. (If you’re not familiar with Hazel, an indespensible Mac utility that everyone should own, here’s a brief intro.)

This rule monitors the folder containing all of my git repositories and highlights any sub-folders that have uncommitted changes. At the end of a work day, it’s a great way to see at a glance which projects have unsaved changes.

Here’s a screenshot of my Hazel rules…

And here’s the shell script that is embedded in rule #1…

1

2

3

4

5

6

7

8

9

10

11

12

13

dirname=$1

if[-f$dirname];then

dirname=`dirname$dirname`

fi

cd$dirname

ifgit status|grep--quiet"working directory clean";then

exit1

else

exit0

fi

As you can see in the first rule, the shell script changes directories into the git project and then pipes git status through grep to check for any changes. Any modified working directories are matched and highlighted red in the Finder.

The second rule un-highlights any folders which don’t get matched – folders with clean working directories.