A productivity tool for blocking websites when you need to focus.
dblock is a command-line tool written in Go for managing the contents of your /etc/hosts file.
- Block/Unblock Domains: Easily add or remove domains from your
/etc/hostsfile. - Scheduling: Schedule blocking or unblocking operations for a specified duration.
- Automatic Subdomains: Automatically handles common subdomains like
www. - Custom Subdomains: Manually specify additional subdomains to block.
- Custom Hosts File Location: Support for custom hosts file paths.
-
Clone the Repository:
git clone https://github.com/dwrtz/dblock.git cd dblock -
Build the Executable:
go build
-
Move Executable to
/usr/local/bin:sudo mv dblock /usr/local/bin
-
Enable Blocking:
sudo dblock enable -
Disable Blocking:
sudo dblock disable
-
Check Status:
dblock status
-
List Configured Domains:
dblock list
On the first run, dblock will create a default configuration file at ~/.dblock/default.yaml if it does not already exist. This file contains a list of sample domains to block.
You can edit this file to specify the domains and subdomains you wish to block.
hosts_file: "/etc/hosts" # Optional: specify custom hosts file location
domains:
- x.com
- twitter.com
- youtube.com
- reddit.com
subdomains:
- blog.example.com
- mail.example.orghosts_file: (Optional) Path to the hosts file. Defaults to/etc/hosts.domains: List of domains to block. Common subdomains likewwware automatically included.subdomains: (Optional) Manually specify additional subdomains to block.
You can specify a custom configuration file using the -c or --config flag.
sudo dblock enable -c /path/to/custom_config.yamlYou can schedule enable or disable operations for a specified duration using the -t or --timeout flag.
-
Block Domains for 60 minutes:
sudo dblock enable -t 60 -
Unblock Domains for 30 minutes:
sudo dblock unblock -t 30
The tool runs an in-process background goroutine that waits (sleep) for the specified duration and then executes the reverse dblock command. If you close the terminal or the system restarts before the timeout elapses, the scheduled operation will not occur.
dblock uses the ~/.dblock directory to store configurations, backups, and logs.
~/.dblock/default.yaml: Your editable config file for specifying domains to block.- Backups: Before modifying the hosts file, a backup is stored in
~/.dblock/backups/. - Logs: Operation logs are stored in
~/.dblock/logs/.
To uninstall dblock:
- Remove the Executable:
sudo rm /usr/local/bin/dblock
- Remove the
~/.dblockDirectory:rm -rf ~/.dblock
This project is licensed under the MIT License. See the LICENSE file for more details.