Skip to content

Instantly share code, notes, and snippets.

@drhodes
Created August 16, 2018 22:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drhodes/c1ce517c1704d4daedef73259b0c60c2 to your computer and use it in GitHub Desktop.
Save drhodes/c1ce517c1704d4daedef73259b0c60c2 to your computer and use it in GitHub Desktop.
# -*- sh -*-
#!/usr/bin/env bash
TMPFILE=/tmp/selfcontrol.temp
# remove self control from hosts
cat /etc/hosts | grep -v self-control > $TMPFILE
echo "# self-control" >> $TMPFILE
# if self control ON
if [[ $1 != "on" ]]
then if [[ $1 != "off" ]]
then echo "Expecting cmd line arg [on|off]"
exit 1
fi
fi
cat ~/.selfcontrol | while read line
do
if [[ $1 == "on" ]]
then
echo 127.0.0.1 $line \# self-control >> $TMPFILE
fi
done
cp $TMPFILE /etc/hosts
rm $TMPFILE
@drhodes
Copy link
Author

drhodes commented Aug 16, 2018

before using, you'll need to: sudo chown $USER /etc/hosts

also you need a file called ~/.selfcontrol with newline separated domain names

to activate filter:
$ selfcontrol on

to remove filter
$ selfcontrol off

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment