Skip to content

Edit your host file for quickly blocking or unblocking distracting sites

Notifications You must be signed in to change notification settings

matthew-webber/distraction-destroyer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 

Repository files navigation

distraction-destroyer 🕉

🐲 Vanquish the enemies of focus and get back to what matters...

In other words, use this script to:

  • block distracting sites by pointing them at the loopback address in your OS's /etc/hosts file
  • unblock / remove sites added to /etc/hosts
  • edit the list of sites to block in a minimal .txt file

Overview

Installation

🖥 Mac/Linux

cd ~
git clone https://github.com/matthew-webber/distraction-destroyer.git
# ...

sudo ./distraction-destroyer/distraction-destroyer.sh

Alternatively, you can install by downloading the project ZIP

  1. Navigate to the top of this page and click 'Code' > 'Download ZIP'
  2. Save the file as-is in your home folder
  3. Rename the unzipped project folder as distraction-destroyer.

Project ZIP location

💾 Windows - requires WSL 1 / WSL 2

If WSL is installed, open one of the below as administrator:

  • Command Prompt
  • Powershell
  • Windows Terminal (bonus: emoji support 👍)
bash # will start the Bash terminal
cd ~
git clone https://github.com/matthew-webber/distraction-destroyer.git
# ...

sudo ./distraction-destroyer/distraction-destroyer.sh

If WSL is not installed, see "Install WSL for Windows"

Create a shortcut

Note: after installing, it is highly recommended to create an alias (shortcut) to distraction-destroyer in your ~/.zshrc or ~/.bashrc file.

Creating an alias (shortcut) to distraction-destroyer will allow you to quickly block sites from anywhere in the terminal (i.e. without being in the project root directory). You can do so by copy+pasting the below into your terminal.

zsh (macOS 10.15 Catalina or later)

echo -e "#distraction-destroyer shortcut (https://github.com/matthew-webber/distraction-destroyer)\nalias distraction-destroyer='sudo ~/distraction-destroyer/distraction-destroyer.sh'" >> ~/.zshrc && zsh

bash (macOS 10.14 Mojave or earlier, Linux, Windows WSL 1 / WSL 2)

echo -e "#distraction-destroyer shortcut (https://github.com/matthew-webber/distraction-destroyer)\nalias distraction-destroyer='sudo ~/distraction-destroyer/distraction-destroyer.sh'" >> ~/.bashrc && bash

Using distraction-destroyer (DD)

Before you start: It is recommended that you create an alias to run distraction-destroyer from the terminal without being in the project root. See Create a shortcut above.

To run DD after installation:

# No alias/shortcut
sudo ./distraction-destroyer/distraction-destroyer.sh

# Shortcut/alias
sudo distraction-destroyer

🙅‍♂️ Blocking sites

  • When you run distraction-destroyer.sh from the Terminal, the script will run automatically. DD will initiate a short countdown before adding each site listed in targets.txt to your hosts file and flushing the DNS cache to wrap-up the process.

🔓 Unblocking sites

  • DD can "resurrect" / unblock sites for you by simply pressing r during the opening countdown. Of course, you can always edit your hosts file yourself at /etc/hosts and remove the lines below the line # distraction-destroyer graveyard (blocked sites).

📝 Editing target sites

  • Each target should be listed in the targets.txt file as "example.com" (i.e. with the domain and top-level domain only) separated by a new line. No need for 'www' — DD takes care of that for you.

  • Editing targets is easy. Either:

    • a) press e* during the countdown, or
    • b) change the targets.txt file using a text editor

* (uses nano so remember to save your changes by pressing ctrl + x , y)


What it does

In its current form, DD is just a fun, lightweight solution for blocking time-wasting sites in your web browser by pointing them at the loopback address¹ (127.0.0.1) in your OS's /etc/hosts file which causes them to fail.²

  • Convenient - edit targets or unblock them from within DD
  • Automatic - DD will do its job automatically and then close — no user input required
  • Intuitive - If a site is already blocked, it will stay blocked. Same goes for unblocking
  • Simple - DD uses a dead-simple process for blocking sites that has been around forever

Who it's for

DD is designed to be a simple tool for computer users of all backgrounds who like to get shit done. Sufferers of ADD/ADHD, students, professionals, or anyone who falls victim to mindless web-browsing when they get stuck in their work may find this project useful.

Philosophy

DD can be considered an alternative to popular "blocking apps" like the ironically named SelfControl but with respect towards a user's autonomy. DD won't stop you from going around it or undoing your changes (but it might give you a hard time!)

The goal is to simply block the initial attempt to visit a trouble site in the hopes that your dopamine-hungry brain "snaps out of it" before you get sucked into mindless browsing. If you actually need to visit the site, just unblock it.

Install WSL for Windows

You can use DD by installing the "Windows Subsystem for Linux" (WSL) which allows you to run Linux commands and interact with the Windows OS. While setup is a bit tedious and includes system resource overhead, the benefit is in knowing that running Linux for Windows is a safe, native solution supported by Microsoft.

The below are simplified instructions for installing the minimum amount of Linux (WSL 1) required to run DD along with a Linux Distro (the most popular distro in this case, Ubuntu). Full instructions here

  1. In the "Turn Windows features on or off" (Control Panel\Programs\Programs and Features) window, enable "Windows Subsystem for Linux"
  2. Reboot
  3. Install and run "Ubuntu" (or any other Linux distro) from the Microsoft Store app and create your username and password
  4. Close Ubuntu

🎉 Congrats! You've installed WSL! 🎉

🐲 Now back to installing DD for Windows...


† If you have the space on your machine, don't care about minimal installs, or just want the easy way: open Powershell as administrator and run the below which will install all of the above in addition to the "Virtual Machine Platform" (WSL2)

wsl --install

🐲 Stay focused, hero...


References

¹ Loopback address (Wikipedia)

² Blocking internet resources (ibid.)

About

Edit your host file for quickly blocking or unblocking distracting sites

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages