iloveitaly / hyper-focus

Block hosts, apps, specific urls (with query string vars!), launch scripts on wake, and generally optimize your productivity and focus
MIT License
50 stars 2 forks source link
digital-minimalism focus focus-management

Hyper Focus

Logo

Hyper Focus is a command line tool that watches your computer activity and prevents you from doing distracting things.

In other words, if you are obsessive about personal productivity you can define what you want a productive day to look like and then use Hyper Focus to enforce it.

This is my first/only project in Swift, so feel to submit PRs to fix obvious things that should be better. Here's what I learned while building this project.

Why do this?

Time is the most valuable + scarce asset. Companies are incentivized to steal your time. Fight back.

Installation

brew install iloveitaly/tap/hyper-focus

You can then start the service as a daemon:

brew services start iloveitaly/tap/hyper-focus

Or run it directly:

hyper-focus

# you may want to run as root if your scripts are modifying system files, like /etc/hosts
sudo hyper-focus --configuration ~/.config/focus/config.json

# for debugging/tinkering, it's helpful to tee the logs
LOG_LEVEL=debug hyper-focus 2>&1 | tee hyper-focus.log

When running via a brew service, the logs are located in $(brew --prefix)/var/log/. You can tail the logs:

tail -f $(brew --prefix)/var/log/hyper_focus.log

Or, download a release build and run it manually.

You'll need to grant accessibility permissions to the binary, which you can find via brew which hyper-focus. If scripts you have defined require root access, you'll also need to grant full disk access to the binary as well.

If permissions get into a weird state, close the app, remove the application from the system permissions list, and then re-add it to the system permissions list.

Running a Brew Service as Root

You may want to run Hyper Focus as root. For instance, if you are modifying the /etc/hosts file on wake, you need to run Hyper Focus as root.

Here's how to do it:

sudo brew services start iloveitaly/tap/hyper-focus

Usage

hyper-focus --help

OVERVIEW: A daemon process which helps you focus on your work.

USAGE: hyper-focus [--version] [--configuration <configuration>]

OPTIONS:
  --version               Print out the version of the application.
  -c, --configuration <configuration>
                          Path to the configuration file
  -h, --help              Show help information.

Configuration

If you are running as root, you'll want to specify the full path to any shell scripts.

Features

Sleepwatching

What is 'first wake'?

'First wake' means the first time the computer is woken from sleep for the current day.

Having a first wake script allows you to tie into something like clean browsers and todoist scheduler to setup your workspace and todo list for the day.

Scheduling

Blocking

Regex

Regex support is a bit weird: add trailing and leading / to the block entry to indicate it's a regex. Think sed-style.

Example:

{
  "block_hosts": [
    // normal
    "google.com",
    // regex!
    "/.*google..*/"
  ]
}

Non-Features

HTTP API

Instead of UI, I've opted to a simple HTTP API that can be used to power a Raycast-based UI.

You can hit the API locally for testing using: http localhost:9029/status

Development

Tests

This is a fun personal tool. Tests are boring, so I didn't write many of them.

Plus, writing tests in Swift seems to be a massive pain (no dynamic mocks!).

Inspiration