Block distracting websites on macOS until you make at least one GitHub commit today.
By default it blocks Gmail (mail.google.com, gmail.com) until your GitHub account has a PushEvent dated today (in your local timezone). The block re-engages automatically every day at 00:01.
- A small shell script (
commit_gate.sh) hits the public GitHub events API for your username. If there's aPushEventtoday, it removes a marked block from/etc/hosts. Otherwise, it adds it. - Two
launchdagents run the script: one every 5 minutes (and at login), and one daily at 00:01 to re-block. - A narrow
sudoersrule lets the script copy a single staged file into/etc/hostswithout prompting for a password each time.
- macOS
- A public GitHub account (private-repo pushes won't show up in the public events API)
python3(preinstalled at/usr/bin/python3on macOS)
git clone https://github.com/<you>/commit_motivation.git
cd commit_motivation
cp .env.example .env
# edit .env and set GITHUB_USER to your github username
$EDITOR .env
bash install.shinstall.sh will:
- Read your
.env - Install a sudoers rule at
/etc/sudoers.d/commit_motivation(asks for your password once) - Render and load two LaunchAgents into
~/Library/LaunchAgents - Run an initial check
Edit .env:
GITHUB_USER=your-github-username
BLOCKED_HOSTS=mail.google.com,www.mail.google.com,gmail.com,www.gmail.comBLOCKED_HOSTS is a comma-separated list. Examples:
# Block Twitter and Reddit instead
BLOCKED_HOSTS=twitter.com,www.twitter.com,x.com,www.x.com,reddit.com,www.reddit.comAfter changing .env, just wait — the next 5-minute poll picks up the new BLOCKED_HOSTS and rewrites /etc/hosts to match. To apply immediately: ./commit_gate.sh check.
./commit_gate.sh check # poll GitHub and toggle the block
./commit_gate.sh status # print BLOCKED or UNBLOCKED
./commit_gate.sh unblock # force-remove the block (next poll may re-add)
./commit_gate.sh reset # force-add the blockLogs: ~/.commit_motivation/gate.log
bash uninstall.shUnloads the LaunchAgents, removes the /etc/hosts block, and deletes the sudoers rule.
This is a soft commitment device, not a hard lock. Anyone who knows what they're doing can sudo vi /etc/hosts and delete the block in 30 seconds, or just disable the LaunchAgent. The friction is the whole point — it's there to interrupt the autopilot of opening Gmail, not to defeat a determined procrastinator.
Other things to know:
- Browser cache: after a hostname is added to
/etc/hosts, browsers may keep an existing tab connected. Cmd+Q (fully quit) and reopen. - Public events only: pushes to private repos don't show up in
/users/<name>/events/public. If you only commit to private repos, this won't work for you. - Fails open: if GitHub's API is unreachable, the script does not block (so you're not stranded with no email when GitHub goes down).
- Local timezone: "today" is your machine's local date, not UTC.
- Doesn't block native apps: this is
/etc/hosts-based, so anything bypassing system DNS (some VPNs, some apps using DoH) will still work. - macOS only: uses
launchdand macOS-style/etc/hostsflushing. Linux would need different scheduling and DNS-flush commands.