Compare commits
3 Commits
Author | SHA1 | Date |
---|---|---|
Arthur POULET | 8aa84b3c95 | |
Arthur POULET | d0d2034aa7 | |
Arthur POULET | c9a2d9cf3f |
14
README.md
14
README.md
|
@ -1,10 +1,18 @@
|
|||
# focus.rb
|
||||
|
||||
A script to help focus by blocking shitty things
|
||||
A script to help focus by blocking shitty things like SOCIAL MERDIA
|
||||
|
||||
## Install
|
||||
|
||||
Requires sudo to write on /etc/hosts
|
||||
|
||||
```
|
||||
gem install focus.rb
|
||||
```
|
||||
|
||||
## How to use
|
||||
|
||||
```
|
||||
sudo focus --block
|
||||
sudo focus --restore
|
||||
focus --block
|
||||
focus --restore
|
||||
```
|
||||
|
|
|
@ -1,16 +1,18 @@
|
|||
#!/usr/bin/env ruby
|
||||
|
||||
require "optparse"
|
||||
require "pry"
|
||||
$LOAD_PATH << File.join(Dir.pwd, "lib")
|
||||
|
||||
require "colorize"
|
||||
require_relative "./focus/config"
|
||||
require_relative "./focus/host"
|
||||
require "optparse"
|
||||
require "focus/config"
|
||||
require "focus/host"
|
||||
|
||||
script_name = File.basename($0)
|
||||
config_path = ".config/focus.rb/config.yaml"
|
||||
action = :list_block_hosts
|
||||
args = []
|
||||
options_parser = nil
|
||||
dry = false
|
||||
|
||||
ARGV.options do |opts|
|
||||
options_parser = opts
|
||||
|
@ -26,6 +28,7 @@ Help to focus on your work, block leasure website while you need working, unbloc
|
|||
|
||||
opts.on("-b", "--block", "Block non-work website") { action = :block }
|
||||
opts.on("-r", "--restore", "Restore non-work website") { action = :restore }
|
||||
opts.on("-d", "--dry", "Don't write on real files") { dry = true }
|
||||
|
||||
opts.separator ""
|
||||
|
||||
|
@ -35,13 +38,15 @@ Help to focus on your work, block leasure website while you need working, unbloc
|
|||
end
|
||||
|
||||
config = Focus::Config.new(filepath: config_path)
|
||||
host_file = "/etc/hosts"
|
||||
host_file = "/dev/null" if dry
|
||||
|
||||
ACTIONS = {
|
||||
list_block_hosts: lambda { puts config.block_hosts },
|
||||
add_block_host: lambda { config.add_block_host(*args) },
|
||||
delete_block_host: lambda { config.add_block_host(*args) },
|
||||
block: lambda { Focus::Host.new.block!(config) },
|
||||
restore: lambda { Focus::Host.new.restore!(config) },
|
||||
block: lambda { Focus::Host.new(host_file).block!(config) },
|
||||
restore: lambda { Focus::Host.new(host_file).restore!(config) },
|
||||
help: lambda { puts options_parser }
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
# coding: utf-8
|
||||
|
||||
Gem::Specification.new do |spec|
|
||||
spec.name = "focus.rb"
|
||||
spec.version = "1.1.0"
|
||||
spec.authors = ["Arthur Poulet"]
|
||||
spec.email = ["arthur.focus@sceptique.eu"]
|
||||
|
||||
spec.summary = "A tool to help you focus on work"
|
||||
spec.description = "A tool to help you focus on work" \
|
||||
"* Block hosts names localy"
|
||||
spec.homepage = "https://git.sceptique.eu/Sceptique/focus.rb"
|
||||
spec.licenses = ["GPL-3.0"]
|
||||
|
||||
spec.files = Dir["lib/**/*.rb", "bin/*"]
|
||||
spec.require_paths = ["lib"]
|
||||
spec.bindir = ["bin"]
|
||||
spec.executables << "focus"
|
||||
|
||||
spec.add_dependency "colorize", "~> 0.8.1"
|
||||
end
|
|
@ -3,15 +3,20 @@ require "yaml"
|
|||
module Focus
|
||||
class Config
|
||||
BASE_PATH = ENV["HOME"]
|
||||
DEFAULT_BLOCK_HOSTS = %w(reddit.com youtube.com okcupid.com)
|
||||
DEFAULT_BLOCK_HOSTS = %w(
|
||||
reddit.com youtube.com facebook.com instagram.com twitter.com
|
||||
linkedin.com snapchat.com tumblr.com pinterest.com tiktok.com
|
||||
)
|
||||
|
||||
def initialize(filepath:)
|
||||
@filepath = File.join(BASE_PATH, filepath)
|
||||
dir = File.dirname(@filepath)
|
||||
if !File.exist?(dir)
|
||||
puts "Create config directory #{dir}"
|
||||
Dir.mkdir(dir)
|
||||
end
|
||||
if !File.exist?(@filepath)
|
||||
puts "Initialize default configuration #{@filepath}"
|
||||
write(
|
||||
{
|
||||
block_hosts: DEFAULT_BLOCK_HOSTS,
|
||||
|
|
|
@ -37,7 +37,9 @@ module Focus
|
|||
end
|
||||
@all_lines << "### FOCUS:stop (automaticaly generated) ###"
|
||||
@all_lines << ""
|
||||
File.write(@file, @all_lines.join("\n"))
|
||||
|
||||
command = "sudo su -c 'echo \"#{@all_lines.join("\n")}\" > #{@file}'"
|
||||
`#{command}`
|
||||
end
|
||||
|
||||
def block!(config)
|
||||
|
|
Loading…
Reference in New Issue