focus.rb 1.0.1 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/focus +10 -4
- data/lib/focus/config.rb +7 -2
- data/lib/focus/host.rb +3 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1df428809adafd42b392926175afb6d8b4ba2919b2aa089d55fe92f8a9f6bc4b
|
4
|
+
data.tar.gz: 1c7218d6b73f81b58a6d9ca6dbafaa26b0b5df57d6a464cf23774886cdf5e7e4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 53c969c851742f456d2fd003e1d738ebf51bac2e1f162c7b351aa7f360659f21b13c702563ae77684848bd5a65ad377ed3fb3649f1ed9e9e9cec9bd9ef972934
|
7
|
+
data.tar.gz: 5893453871608649f0b26bcd84d753acb4768e2d9f256f9f10827bb19d49abe9e45375ea4e37203ad42d1b7f065af3feab4d852b65e13e0fe9dafde24c0341f5
|
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
|
@@ -21,10 +24,11 @@ Help to focus on your work, block leasure website while you need working, unbloc
|
|
21
24
|
opts.on("-c=PATH", "--config=PATH", "Change the default config path") { |path| config_path = path }
|
22
25
|
|
23
26
|
opts.on("-a=BLOCK", "--add-block-host=BLOCK", "Add a new host to block") { |block| action = :add_block_host; args = [block] }
|
24
|
-
opts.on("
|
27
|
+
opts.on("--delete-block-host=BLOCK", "Delete a host to block") { |block| action = :delete_block_host; args = [block] }
|
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
|
-
delete_block_host: lambda { config.
|
42
|
-
block: lambda { Focus::Host.new.block!(config) },
|
43
|
-
restore: lambda { Focus::Host.new.restore!(config) },
|
47
|
+
delete_block_host: lambda { config.delete_block_host(*args) },
|
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(
|
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,
|
@@ -45,7 +50,7 @@ module Focus
|
|
45
50
|
end
|
46
51
|
|
47
52
|
def delete_block_host(blocks)
|
48
|
-
puts "This operation
|
53
|
+
puts "This operation deletes \"#{blocks}\" to the list of blocked hosts.".yellow
|
49
54
|
puts "This operation does not unblock the hosts. Execute -b to refresh the blocking or -r to reset it.".yellow
|
50
55
|
blocks.split(",").each do |block|
|
51
56
|
data = read
|
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
|
-
|
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.
|
4
|
+
version: 1.1.1
|
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:
|
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.
|
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
|