Created
September 30, 2010 20:47
-
-
Save mort/605292 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# My first Thor script is a helper to the productivity strategy of having an | |
# specific /etc/hosts file that blocks Twitter, Facebook, porn sites, and other | |
# unwanted distractions, during certains time of the day. | |
# Copy of your regular hosts file to /etc/hosts.play | |
# Create a /etc/hosts.work file with all the blocked sites on it | |
# Use 'thor lets:do [work|play]' to switch to the desired mental context. | |
# 'work' and 'play' are orientative, use whichever keywords suit you best. | |
# Nothing keeps you from keeping n different 'contexts' around. | |
# Set the DNSFlush_cmd constant to the command used in your OS for that purpose. | |
class Lets < Thor | |
require 'fileutils' | |
Base = '/etc/hosts' | |
Prev = Base+'.prev' | |
DNSflush_cmd = 'dscacheutil -flushcache' | |
desc 'env', 'what are you all about right now' | |
def do(env) | |
file = [Base,env].join('.') | |
raise NoEnv unless File.exists?(file) | |
FileUtils.copy_file(Base,Prev) | |
FileUtils.copy_file(file,Base) | |
system(DNSflush_cmd) | |
puts "You got it. Let's #{env}." | |
end | |
end | |
class NoEnv < StandardError;end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment