Skip to content

Instantly share code, notes, and snippets.

@kmurph73
Last active July 12, 2018 18:42
Show Gist options
  • Save kmurph73/f09c0ce1c9f36064f7dc12b0b2331c78 to your computer and use it in GitHub Desktop.
Save kmurph73/f09c0ce1c9f36064f7dc12b0b2331c78 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
hosts = '/etc/hosts'
lines = []
blocked_sites_section = false
File.open(hosts, 'r') do |f|
while line = f.gets
blocked_sites_section = true if line =~ /blocked\ssites/
blocked_sites_section = false if line =~ /blocked\ssites\send/
if blocked_sites_section && line =~ /^\s*#+\s*127\.0\.0\.1/
line.gsub!(/^\s*#+\s*/, '')
end
lines << line
end
end
File.open(hosts, 'w') do |f|
f.puts lines
end
@kmurph73
Copy link
Author

Put this file in your path (EG /usr/local/bin - name it something like block), then make it executable via chmod +x block. Open a new terminal tab and type sudo block.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment