Hacker News new | ask | show | jobs
by Supreme 4989 days ago
Optimized version:

# turn on

sudo rm /etc/hosts

sudo ln -s /etc/hosts{.work,}

# turn off

sudo rm /etc/hosts

sudo ln -s /etc/hosts{.play,}

Optimized further (in your ~/.bashrc):

alias work="sudo rm /etc/hosts && sudo ln -s /etc/hosts{.work,}"

alias play="sudo rm /etc/hosts && sudo ln -s /etc/hosts{.play,}"

Optimization cubed (lets you define a base hosts file):

alias work="sudo rm /etc/hosts && sudo cat /etc/hosts.base >> /etc/hosts && sudo cat /etc/hosts.work >> /etc/hosts"

alias play=...

The number of upvotes, the fact that you thought this was necessary and the fact that this application exists all made me facepalm hard. I can't even see right now.

2 comments

This is close to what I have, except less complex. A single line in /etc/hosts that redirects sites to 127.0.0.1, which gets commented or uncommented. The fact that I have to go through the hassle of sudoing up and removing the comment means I'm far more likely to catch myself before doing it and getting back to work.
Optimization #4:

alias play="sleep 120 && ..."

Two minutes should be enough for the craving to pass :-)

I upvoted so that others share their similar setups/scripts (as you did).