dblock

command module
v0.0.0-...-ab1e6b3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 16, 2024 License: MIT Imports: 15 Imported by: 0

README

dblock

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.

Features

  • Block/Unblock Domains: Easily add or remove domains from your /etc/hosts file.
  • 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.

Table of Contents

Installation

  1. Clone the Repository:

    git clone https://github.com/dwrtz/dblock.git
    cd dblock
    
  2. Build the Executable:

    go build
    
  3. Move Executable to /usr/local/bin:

    sudo mv dblock /usr/local/bin
    

Usage

Basic Commands
  • Enable Blocking:

    sudo dblock enable
    
  • Disable Blocking:

    sudo dblock disable
    
  • Check Status:

    dblock status
    
  • List Configured Domains:

    dblock list
    

Configuration

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.

Sample Configuration
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.org
  • hosts_file: (Optional) Path to the hosts file. Defaults to /etc/hosts.
  • domains: List of domains to block. Common subdomains like www are automatically included.
  • subdomains: (Optional) Manually specify additional subdomains to block.
Custom Configuration File

You can specify a custom configuration file using the -c or --config flag.

sudo dblock enable -c /path/to/custom_config.yaml

Scheduling Operations

You can schedule enable or disable operations for a specified duration using the -t or --timeout flag.

Examples
  • Block Domains for 60 minutes:

    sudo dblock enable -t 60
    
  • Unblock Domains for 30 minutes:

    sudo dblock unblock -t 30
    
How Scheduling Works

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.

The ~/.dblock Folder

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/.

Uninstallation

To uninstall dblock:

  1. Remove the Executable:
    sudo rm /usr/local/bin/dblock
    
  2. Remove the ~/.dblock Directory:
    rm -rf ~/.dblock
    

License

This project is licensed under the MIT License. See the LICENSE file for more details.

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL