Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?

##Mac GitWatch

Based heavily on: https://gist.github.com/kbdluv/0ad7effe175e5f52d79078f422eab463#file-git-watch-sh

This watches the list of dirs in $repos. Remove mine and add your own. It will watch for changes and then commit and push the result.

To make this run and stay alive, you have to use automator to make an Application script.

Source: https://stackoverflow.com/questions/6442364/running-script-upon-login-mac

Here's a screenshot of what I did: https://stackoverflow.com/questions/6442364/running-script-upon-login-mac

Then you can run this app on login with the plist below.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.gitwatch</string>
<key>KeepAlive</key>
<true/>
<key>Program</key>
<string>/Applications/gitwatch.app/Contents/MacOS/Application\U00A0Stub</string>
</dict>
</plist>
#!/bin/bash
cd "$1" && git add . && git commit -m "unattended" && git push
#!/bin/bash
# PATH for launchd to find `fswatch`
export PATH="/usr/local/bin:$PATH"
repos=(
'/Users/jeremy/Dropbox/Writer/MyNovel'
'/Users/jeremy/Dropbox/Writer/Journal'
);
sleeptime=300
for repo in ${repos[*]}
do
echo $repo
fswatch -r "$repo" | (sleep $sleeptime; grep --line-buffered -v '\/.git\/';) | xargs -n1 -I{} /Users/Jeremy/bin/git-commit-unattended.sh "$repo" &
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.