Last active
July 12, 2018 18:42
-
-
Save kmurph73/f09c0ce1c9f36064f7dc12b0b2331c78 to your computer and use it in GitHub Desktop.
This file contains 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
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Put this file in your path (EG
/usr/local/bin
- name it something likeblock
), then make it executable viachmod +x block
. Open a new terminal tab and typesudo block
.