Block websites on your system with /etc/hosts, and re-enable them on demand for a specified amount of time.
brew install cdzombak/oss/hosts-timerInstall my Debian repository if you haven't already:
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://dist.cdzombak.net/keys/dist-cdzombak-net.gpg -o /etc/apt/keyrings/dist-cdzombak-net.gpg
sudo chmod 644 /etc/apt/keyrings/dist-cdzombak-net.gpg
sudo mkdir -p /etc/apt/sources.list.d
sudo curl -fsSL https://dist.cdzombak.net/cdzombak-oss.sources -o /etc/apt/sources.list.d/cdzombak-oss.sources
sudo chmod 644 /etc/apt/sources.list.d/cdzombak-oss.sources
sudo apt updateThen install hosts-timer via apt-get:
sudo apt-get install hosts-timerPre-built binaries for Linux and macOS on various architectures are downloadable from each GitHub Release. Debian packages for each release are available as well.
Requires Go to be installed:
git clone https://github.com/cdzombak/hosts-timer.git
cd hosts-timer
make installsudo hosts-timer -install facebook.com twitter.com(-disable is an alias for -install, which disables the given sites.)
sudo hosts-timer -time 5m twitter.comDurations must be acceptable by time.ParseDuration.
sudo hosts-timer -uninstall twitter.com facebook.com(-enable is an alias for -uninstall, which enables the given sites.)
function use-facebook() {
if [ $# -eq 0 ]; then
echo "Usage: use-facebook DURATION"
echo " eg. use-facebook 5m"
return 1
fi
sudo hosts-timer -time "$1" facebook.com
}
function use-twitter() {
if [ $# -eq 0 ]; then
echo "Usage: use-twitter DURATION"
echo " eg. use-twitter 5m"
return 1
fi
sudo hosts-timer -time "$1" twitter.com
}Install the included Alfred helpers, and then you can use Alfred to enable Twitter or Facebook for a given amount of time (default 5 minutes).
cdzombak ALL=NOPASSWD: /usr/local/bin/hosts-timer
And then:
sudo chown root:wheel /etc/sudoers.d/hosts-timer
sudo chmod 440 /etc/sudoers.d/hosts-timer
Chris Dzombak
