--- /dev/null
+#!/bin/bash
+
+if [ "x$1" == "xdoit" ]; then
+ # fetch everything
+ git fetch;
+ # figure out if we should pull
+ # 1. no modified files
+ if [ -n "$(git status --porcelain -u no)" ]; then
+ # 2. Not detached head
+ if [ -n "$(git symbolic-ref HEAD)" ]; then
+ # 3. no commits which are not in origin
+ if [ -n "$(git rev-list \"^$(git remote|head -n 1)\" HEAD)" ]; then
+ # 3. machine is currently inactive for more than 1 hour
+ if [ "$IDLE_TIME" -gt 3600 ]; then
+ git pull;
+ fi;
+ fi;
+ fi;
+ fi;
+
+
+else
+ IDLE_TIME=0
+ if which xprintidle >/dev/null 2>&1; then
+ IDLE_TIME=$(($(xprintidle) / 1000 ));
+ fi;
+ IDLE_TIME="$IDLE_TIME" mr -d ~ -j5 run update_git_repos doit;
+fi;