Git Product home page Git Product logo

hosts-timer's Introduction

hosts-timer

Block websites on your system with /etc/hosts, and re-enable them on demand for a specified amount of time.

Installation

Requires Go to be installed (tested with Go 1.15.x).

git clone https://github.com/cdzombak/hosts-timer.git
cd hosts-timer
make install

Usage

Setup for domain(s)

sudo hosts-timer -install facebook.com twitter.com

(-disable is an alias for -install, which disables the given sites.)

Use a site for a specified duration of time

sudo hosts-timer -time 5m twitter.com

Durations must be acceptable by time.ParseDuration.

Remove hosts-timer block for domain(s)

sudo hosts-timer -uninstall twitter.com facebook.com

(-enable is an alias for -uninstall, which enables the given sites.)

Setup Hints

.zshrc helpers

function use-facebook() {
    if [ $# -eq 0 ]; then
        echo "Usage: use-facebook DURATION"
        echo "   eg. use-facebook 5m"
        return 1
    fi
    sudo hosts-timer -time "$1" facebook.com
}

function use-twitter() {
    if [ $# -eq 0 ]; then
        echo "Usage: use-twitter DURATION"
        echo "   eg. use-twitter 5m"
        return 1
    fi
    sudo hosts-timer -time "$1" twitter.com
}

Alfred helpers

Install the included Alfred helpers, and then you can use Alfred to enable Twitter or Facebook for a given amount of time (default 5 minutes).

Screenshot of Alfred helper for Twitter

Create /etc/sudoers.d/hosts-timer

cdzombak ALL=NOPASSWD: /usr/local/bin/hosts-timer

And then:

sudo chown root:wheel /etc/sudoers.d/hosts-timer
sudo chmod 440 /etc/sudoers.d/hosts-timer

Author

Chris Dzombak

hosts-timer's People

Contributors

cdzombak avatar

Stargazers

Mike Zornek avatar

Watchers

 avatar James Cloos avatar

hosts-timer's Issues

Cannot support both IPv4 and IPv6

When using https://github.com/txn2/txeh to add ipv4 and then ipv6 entries to hosts, it will always remove all previous entries regardless of IP version. So, trying to add ipv6 after ipv4 means the ipv4 entries get removed, and vice versa.

I can't really handle this, without patching the underlying lib. But ipv6 is currently disabled at home for Other Reasons, so ¯\_(ツ)_/¯

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.