FocusPocus is a tiny Bash spell that toggles distractions on or off by rewriting /etc/hosts. It flips between focus (only work) and pocus (temporary play) so you can keep social sites out of reach until you truly earn the break. The project is authored by Mike Lopez.
- Works entirely through
/etc/hosts, so it is desktop-environment agnostic. - Uses
#distractionmarkers to decide which hostnames should be blocked or unblocked. focus(default) instantly re-enables blocking and prints a success banner when the command completes.pocusrequires solving two random multiplication challenges before unblocking, helping you pause before drifting off-task.- All logic lives in a single portable Bash script; no daemons or background services.
- Bash 4+, Perl (the script now checks for it and exits early if missing), and
sudoaccess (FocusPocus callssudo perl -pito edit/etc/hosts). /etc/hostsentries annotated with#distractionfor every site you want FocusPocus to manage.- macOS, Linux, or any Unix-like OS where editing
/etc/hostsis effective.
- Copy the
focuspocusscript somewhere in yourPATH, e.g./usr/local/bin/focuspocus. - Mark it executable:
chmod +x /usr/local/bin/focuspocus.- Fast install one-liner (downloads the script directly from
main):(sudo curl -fsSL https://raw.githubusercontent.com/easterncoder/focuspocus/main/focuspocus -o /usr/local/bin/focuspocus || sudo wget -qO /usr/local/bin/focuspocus https://raw.githubusercontent.com/easterncoder/focuspocus/main/focuspocus) && sudo chmod +x /usr/local/bin/focuspocus
- Fast install one-liner (downloads the script directly from
- Add distraction entries to
/etc/hosts, for example:127.0.0.1 facebook.com www.facebook.com #distraction 127.0.0.1 twitter.com www.twitter.com #distraction 127.0.0.1 youtube.com www.youtube.com #distraction - (Optional) Create a backup copy of
/etc/hostsin case you need to restore it later.
# Block distracting sites (default)
focuspocus
# Explicit focus mode block
focuspocus focus
# Attempt to unblock (requires two correct math answers)
focuspocus pocusfocus: Runssudo perl -pi -e 's/^[#\s]+(.+?#distraction)/\1/' /etc/hoststo uncomment every distraction line and re-enable blocking, then prints a confirmation banner. If the edit fails, you will see an error banner instead.pocus: Prints a warning, then asks two multiplication questions (one single digit × one double digit). Only if both are correct does it comment out each distraction line (#prefix) and allow access. Any incorrect answer or editing error leaves the block in place and produces a failure banner.
- Add or remove hostnames by editing
/etc/hostsand keeping#distractionon every line you want the script to control. - Lines without
#distractionare untouched, so you can safely keep other overrides or local domains in the file. - Use IPv6 (
::1) entries as well if your browser prefers IPv6; just append#distractionso FocusPocus can find them.
- FocusPocus modifies
/etc/hostsdirectly. Always verify the file after big changes or keep it under version control. - Commands run with
sudo, so you will be prompted for your password; cancel withCtrl+Cif something looks wrong. - If the script appears ineffective, flush your DNS cache or toggle network interfaces so the OS loads the new
hostsentries.
FocusPocus is distributed under the GNU General Public License v3.0 or later. See the script header for the full notice or visit https://www.gnu.org/licenses/.