focus.rb 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: be3ca51dc59f5a69a6b15b2381b7596776c7a85b656f2402db409ef11a095e0a
4
- data.tar.gz: dfed043bd5a771f9ecc8ad7e22eb898349bbece9cb5c9520da50cf37256e7390
3
+ metadata.gz: 9dae74d714f49abf09ba3d42f7831f05760346563dd4cce4a233b6f0975020c4
4
+ data.tar.gz: a2b268db17e8ff009b7d1b672499f5fbbb7cfff6b0f76a66c2c352c3a7767325
5
5
  SHA512:
6
- metadata.gz: a551d74afb999598545732fe17a94f0e96581b44a6b06e3ea6cce87fab20f66ed51cda65715238abc8c1612fb468b2f72f4774e4ad81ed96310bd35c2c897311
7
- data.tar.gz: 3230ffd2acd77850eaf32bd2eb01b3bf150bd531beaa291c3d3cee11cf5f2821ab1307cef3f0e16dc78f56cb0ce32bf29c70b1769835868afa85faa3e2a9f612
6
+ metadata.gz: 04d3b1ebf9df3df68e3fb2f79fa3ce793b46346b886163ba61cd040d2c467ccaabc64cc25e6a90527dbbb08d3ea941da773172eed5b36e762022f0ca6db57810
7
+ data.tar.gz: 8f66742d9f3684b84555548b26a983bf70eb34e81f411ef720bc2e58a910b95cd003c6686ddc4c29564344c6d56fc683a0e9f1a69f913a61db9ed28550f62658
data/bin/focus CHANGED
@@ -1,5 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ $LOAD_PATH << File.join(Dir.pwd, "lib")
4
+
3
5
  require "colorize"
4
6
  require "optparse"
5
7
  require "focus/config"
@@ -10,6 +12,7 @@ config_path = ".config/focus.rb/config.yaml"
10
12
  action = :list_block_hosts
11
13
  args = []
12
14
  options_parser = nil
15
+ dry = false
13
16
 
14
17
  ARGV.options do |opts|
15
18
  options_parser = opts
@@ -25,6 +28,7 @@ Help to focus on your work, block leasure website while you need working, unbloc
25
28
 
26
29
  opts.on("-b", "--block", "Block non-work website") { action = :block }
27
30
  opts.on("-r", "--restore", "Restore non-work website") { action = :restore }
31
+ opts.on("-d", "--dry", "Don't write on real files") { dry = true }
28
32
 
29
33
  opts.separator ""
30
34
 
@@ -34,13 +38,15 @@ Help to focus on your work, block leasure website while you need working, unbloc
34
38
  end
35
39
 
36
40
  config = Focus::Config.new(filepath: config_path)
41
+ host_file = "/etc/hosts"
42
+ host_file = "/dev/null" if dry
37
43
 
38
44
  ACTIONS = {
39
45
  list_block_hosts: lambda { puts config.block_hosts },
40
46
  add_block_host: lambda { config.add_block_host(*args) },
41
47
  delete_block_host: lambda { config.add_block_host(*args) },
42
- block: lambda { Focus::Host.new.block!(config) },
43
- restore: lambda { Focus::Host.new.restore!(config) },
48
+ block: lambda { Focus::Host.new(host_file).block!(config) },
49
+ restore: lambda { Focus::Host.new(host_file).restore!(config) },
44
50
  help: lambda { puts options_parser }
45
51
  }
46
52
 
data/lib/focus/config.rb CHANGED
@@ -3,15 +3,20 @@ require "yaml"
3
3
  module Focus
4
4
  class Config
5
5
  BASE_PATH = ENV["HOME"]
6
- DEFAULT_BLOCK_HOSTS = %w(reddit.com youtube.com okcupid.com)
6
+ DEFAULT_BLOCK_HOSTS = %w(
7
+ reddit.com youtube.com facebook.com instagram.com twitter.com
8
+ linkedin.com snapchat.com tumblr.com pinterest.com tiktok.com
9
+ )
7
10
 
8
11
  def initialize(filepath:)
9
12
  @filepath = File.join(BASE_PATH, filepath)
10
13
  dir = File.dirname(@filepath)
11
14
  if !File.exist?(dir)
15
+ puts "Create config directory #{dir}"
12
16
  Dir.mkdir(dir)
13
17
  end
14
18
  if !File.exist?(@filepath)
19
+ puts "Initialize default configuration #{@filepath}"
15
20
  write(
16
21
  {
17
22
  block_hosts: DEFAULT_BLOCK_HOSTS,
data/lib/focus/host.rb CHANGED
@@ -37,7 +37,9 @@ module Focus
37
37
  end
38
38
  @all_lines << "### FOCUS:stop (automaticaly generated) ###"
39
39
  @all_lines << ""
40
- File.write(@file, @all_lines.join("\n"))
40
+
41
+ command = "sudo su -c 'echo \"#{@all_lines.join("\n")}\" > #{@file}'"
42
+ `#{command}`
41
43
  end
42
44
 
43
45
  def block!(config)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: focus.rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arthur Poulet
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir:
10
10
  - bin
11
11
  cert_chain: []
12
- date: 2021-09-21 00:00:00.000000000 Z
12
+ date: 2023-06-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: colorize
@@ -55,7 +55,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
55
55
  - !ruby/object:Gem::Version
56
56
  version: '0'
57
57
  requirements: []
58
- rubygems_version: 3.2.27
58
+ rubygems_version: 3.3.22
59
59
  signing_key:
60
60
  specification_version: 4
61
61
  summary: A tool to help you focus on work