sheldon 0.4.1 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/sheldon +56 -22
- data/lib/sheldon/brain.rb +27 -23
- data/lib/sheldon/builder.rb +4 -1
- data/lib/sheldon/helpers.rb +5 -5
- data/lib/sheldon/memory.rb +19 -9
- data/lib/sheldon/sheldon.rb +15 -11
- metadata +21 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 09ae36b8d2caa6f99c7615897f8be3f0307d2046
|
4
|
+
data.tar.gz: 983e9c673075ade9d355051d478ba2d5384c27a0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 574459c5e4af0e7039ff69d9c2e23ad53830414961cbed245a478966f7eb685cfff85b023d324cf0991240aeabf8d8f946857c8f77e9a93d91f120a3c7dc2fee
|
7
|
+
data.tar.gz: 52be880c55eab8afbd7f9f34524179a74b55b5f5ebf60b6c790a119d83bc54ed75adf39b800a540a96ab989a04b7998aebd7b004cfec44fd244eac114f7aff24
|
data/bin/sheldon
CHANGED
@@ -9,13 +9,22 @@ module CLI
|
|
9
9
|
map "-v" => :version
|
10
10
|
map "--version" => :version
|
11
11
|
|
12
|
+
class_option :debug, :desc => "Print errors and backtraces to the console for debugging."
|
13
|
+
|
12
14
|
desc "build path", "Tell Sheldon to build all config_ files in a directory to single master config"
|
13
15
|
def build(rel_path_to_target)
|
14
|
-
|
15
|
-
with_exception_handling{ sheldon.build(
|
16
|
+
abs_build_path = File.expand_path(rel_path_to_target)
|
17
|
+
with_exception_handling{ sheldon.build(abs_build_path) }
|
16
18
|
announce("Built #{File.basename(rel_path_to_target)}")
|
17
19
|
end
|
18
20
|
|
21
|
+
desc "forget recall_cue", "Remove file/folder from Sheldon's brain"
|
22
|
+
def forget(recall_cue=nil)
|
23
|
+
recall_cue ||= prompt_user("Recall Cue For File/Folder")
|
24
|
+
with_exception_handling { sheldon.forget(recall_cue) }
|
25
|
+
announce("I've forgotten about #{recall_cue}. Let us never mention it again.")
|
26
|
+
end
|
27
|
+
|
19
28
|
desc "learn path", "Add a new file/folder to Sheldon's brain. Supply a recall_cue at runtime."
|
20
29
|
def learn(rel_path_to_target)
|
21
30
|
abs_learn_path = File.expand_path(rel_path_to_target)
|
@@ -25,6 +34,13 @@ module CLI
|
|
25
34
|
with_exception_handling { sheldon.recall(recall_cue) }
|
26
35
|
end
|
27
36
|
|
37
|
+
desc "list", "List all recall cues known by Sheldon"
|
38
|
+
def list
|
39
|
+
sheldon.list_cues.each do |recall_cue|
|
40
|
+
sheldon.recalled?(recall_cue) ? green(recall_cue) : red(recall_cue)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
28
44
|
desc "recall recall_cue", "Symlink a previously learnt file/directory to it's original location on the filesystem.\nUse `sheldon list` for available cues."
|
29
45
|
option :i, type: :boolean, desc: "Interactive mode - prompts Y/N for each available recall_cue"
|
30
46
|
|
@@ -42,17 +58,21 @@ module CLI
|
|
42
58
|
announce("Recall Complete.")
|
43
59
|
end
|
44
60
|
|
45
|
-
desc "
|
46
|
-
def
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
61
|
+
desc "setup path_to_data_directory", "Setup Sheldon on this host, supplying the path that where Sheldon's data directory can be found, or should be created."
|
62
|
+
def setup(rel_data_path=nil)
|
63
|
+
rel_data_path ||= prompt_user("Please supply location for new/existing data directory")
|
64
|
+
abs_data_path = File.expand_path(rel_data_path)
|
65
|
+
with_exception_handling do
|
66
|
+
sheldon = ::Sheldon.new(abs_data_path)
|
67
|
+
|
68
|
+
if sheldon.brain.present?
|
69
|
+
green "Using existing Sheldon database found at #{abs_data_path}."
|
70
|
+
else
|
71
|
+
sheldon.setup!
|
72
|
+
green "New Sheldon database created at #{abs_data_path}"
|
73
|
+
end
|
51
74
|
|
52
|
-
|
53
|
-
def list
|
54
|
-
sheldon.list_cues.each do |recall_cue|
|
55
|
-
sheldon.recalled?(recall_cue) ? green(recall_cue) : red(recall_cue)
|
75
|
+
write_to_dotfile("data_directory", sheldon.brain.location)
|
56
76
|
end
|
57
77
|
end
|
58
78
|
|
@@ -63,41 +83,55 @@ module CLI
|
|
63
83
|
|
64
84
|
private
|
65
85
|
|
86
|
+
def announce(message)
|
87
|
+
logo = "💥".encode("utf-8")
|
88
|
+
puts logo + " Sheldon" + logo + " #{message}"
|
89
|
+
end
|
90
|
+
|
91
|
+
def green(message)
|
92
|
+
puts "\e[32m#{message}\e[0m"
|
93
|
+
end
|
94
|
+
|
66
95
|
def prompt_user(prompt)
|
67
96
|
print(prompt + ": ")
|
68
97
|
input = STDIN.gets.chomp.strip
|
69
98
|
input.empty? ? nil : input
|
70
99
|
end
|
71
100
|
|
72
|
-
def
|
73
|
-
|
101
|
+
def read_from_dotfile(key)
|
102
|
+
dotfile = YAML::Store.new(add_home(".sheldon"))
|
103
|
+
dotfile.transaction { dotfile[key] }
|
74
104
|
end
|
75
105
|
|
76
106
|
def red(message)
|
77
107
|
puts "\e[31m#{message}\e[0m"
|
78
108
|
end
|
79
109
|
|
80
|
-
def announce(message)
|
81
|
-
logo = "💥".encode("utf-8")
|
82
|
-
puts logo + " Sheldon" + logo + " #{message}"
|
83
|
-
end
|
84
|
-
|
85
110
|
def sheldon
|
86
111
|
with_exception_handling { @sheldon ||= ::Sheldon.new(sheldon_data_dir) }
|
87
112
|
end
|
88
113
|
|
89
114
|
def sheldon_data_dir
|
90
|
-
|
91
|
-
|
115
|
+
sheldon_data_dir = read_from_dotfile("data_directory") || ENV['SHELDON_DATA_DIR']
|
116
|
+
sheldon_data_dir || raise("No configuration found. Please run `sheldon setup`")
|
92
117
|
end
|
93
118
|
|
94
119
|
def with_exception_handling(&block)
|
95
120
|
yield
|
96
121
|
rescue Exception => e
|
97
|
-
|
122
|
+
if options[:debug]
|
123
|
+
puts ([e.inspect] + e.backtrace).join("\n")
|
124
|
+
else
|
125
|
+
red(e.message + "\nUse --debug to print backtrace")
|
126
|
+
end
|
98
127
|
exit(1)
|
99
128
|
end
|
100
129
|
|
130
|
+
def write_to_dotfile(key, value)
|
131
|
+
dotfile = YAML::Store.new(add_home(".sheldon"))
|
132
|
+
dotfile.transaction { dotfile[key] = value }
|
133
|
+
end
|
134
|
+
|
101
135
|
end
|
102
136
|
end
|
103
137
|
|
data/lib/sheldon/brain.rb
CHANGED
@@ -1,12 +1,25 @@
|
|
1
1
|
class Brain
|
2
2
|
|
3
|
-
attr_reader :memory
|
3
|
+
attr_reader :memory, :location
|
4
4
|
|
5
|
-
def initialize(sheldon_data_dir
|
6
|
-
@
|
7
|
-
@memory =
|
5
|
+
def initialize(sheldon_data_dir)
|
6
|
+
@location = sheldon_data_dir
|
7
|
+
@memory = Memory.new(@location)
|
8
8
|
end
|
9
9
|
|
10
|
+
def forget(recall_cue)
|
11
|
+
entry = memory.recall(recall_cue)
|
12
|
+
brain_path = brain_path_for_cue(recall_cue)
|
13
|
+
destination_path = add_home(entry[:filepath])
|
14
|
+
FileUtils.rm_r(destination_path) if recalled?(recall_cue)
|
15
|
+
FileUtils.rm_r(brain_path)
|
16
|
+
|
17
|
+
memory.forget(recall_cue)
|
18
|
+
end
|
19
|
+
|
20
|
+
def has_cue?(recall_cue)
|
21
|
+
memory.has_cue?(recall_cue)
|
22
|
+
end
|
10
23
|
|
11
24
|
def learn(recall_cue, abs_learn_path)
|
12
25
|
raise "recall cue cannot be empty." if recall_cue.strip.empty?
|
@@ -20,6 +33,14 @@ class Brain
|
|
20
33
|
memory.add(recall_cue, entry)
|
21
34
|
end
|
22
35
|
|
36
|
+
def list_cues
|
37
|
+
memory.list_cues
|
38
|
+
end
|
39
|
+
|
40
|
+
def present?
|
41
|
+
memory.present?
|
42
|
+
end
|
43
|
+
|
23
44
|
def recall(recall_cue)
|
24
45
|
entry = memory.recall(recall_cue)
|
25
46
|
destination_path = add_home(entry[:filepath])
|
@@ -27,16 +48,7 @@ class Brain
|
|
27
48
|
FileUtils.mkdir_p(destination_dir) unless File.directory?(destination_dir)
|
28
49
|
brain_path = brain_path_for_cue(recall_cue)
|
29
50
|
FileUtils.ln_s(get_content(brain_path), destination_path, force: true)
|
30
|
-
|
31
|
-
|
32
|
-
def forget(recall_cue)
|
33
|
-
entry = memory.recall(recall_cue)
|
34
|
-
brain_path = brain_path_for_cue(recall_cue)
|
35
|
-
destination_path = add_home(entry[:filepath])
|
36
|
-
FileUtils.rm_r(destination_path) if recalled?(recall_cue)
|
37
|
-
FileUtils.rm_r(brain_path)
|
38
|
-
|
39
|
-
memory.forget(recall_cue)
|
51
|
+
return true
|
40
52
|
end
|
41
53
|
|
42
54
|
def recalled?(recall_cue)
|
@@ -47,22 +59,14 @@ class Brain
|
|
47
59
|
File.symlink?(destination_path) && File.exists?(File.readlink(destination_path))
|
48
60
|
end
|
49
61
|
|
50
|
-
def has_cue?(recall_cue)
|
51
|
-
memory.has_cue?(recall_cue)
|
52
|
-
end
|
53
|
-
|
54
62
|
def size
|
55
63
|
memory.size
|
56
64
|
end
|
57
65
|
|
58
|
-
def list_cues
|
59
|
-
memory.list_cues
|
60
|
-
end
|
61
|
-
|
62
66
|
private
|
63
67
|
|
64
68
|
def brain_path_for_cue(recall_cue)
|
65
|
-
File.join(@
|
69
|
+
File.join(@location, recall_cue)
|
66
70
|
end
|
67
71
|
|
68
72
|
def get_content(path)
|
data/lib/sheldon/builder.rb
CHANGED
@@ -7,9 +7,12 @@ class Builder
|
|
7
7
|
is_config?(entry) ? add_entry_to_buffer(entry, buffer) : buffer
|
8
8
|
end
|
9
9
|
|
10
|
-
|
10
|
+
if master_content.empty?
|
11
|
+
return false
|
12
|
+
else
|
11
13
|
master_path = File.join(abs_build_path, "config")
|
12
14
|
File.open(master_path, "w") { |f| f.write(master_content) }
|
15
|
+
return true
|
13
16
|
end
|
14
17
|
end
|
15
18
|
|
data/lib/sheldon/helpers.rb
CHANGED
@@ -1,9 +1,8 @@
|
|
1
1
|
module Helpers
|
2
2
|
require "pathname"
|
3
3
|
|
4
|
-
def
|
5
|
-
|
6
|
-
Pathname(path).relative_path_from(home_path).to_s
|
4
|
+
def abs(rel_path)
|
5
|
+
File.expand_path(rel_path).to_s
|
7
6
|
end
|
8
7
|
|
9
8
|
def add_home(path)
|
@@ -11,8 +10,9 @@ module Helpers
|
|
11
10
|
File.join(abs_home, path).to_s
|
12
11
|
end
|
13
12
|
|
14
|
-
def
|
15
|
-
File.expand_path(
|
13
|
+
def remove_home(path)
|
14
|
+
home_path = Pathname(File.expand_path("~"))
|
15
|
+
Pathname(path).relative_path_from(home_path).to_s
|
16
16
|
end
|
17
17
|
|
18
18
|
end
|
data/lib/sheldon/memory.rb
CHANGED
@@ -12,28 +12,38 @@ class Memory
|
|
12
12
|
@database.transaction do
|
13
13
|
@database[recall_cue] = hash
|
14
14
|
end
|
15
|
-
|
16
|
-
|
17
|
-
def recall(recall_cue)
|
18
|
-
raise "no entry for cue '#{recall_cue}'" unless has_cue?(recall_cue)
|
19
|
-
@database.transaction { @database[recall_cue] }
|
15
|
+
return true
|
20
16
|
end
|
21
17
|
|
22
18
|
def forget(recall_cue)
|
23
19
|
raise "no entry for cue" unless has_cue?(recall_cue)
|
24
20
|
@database.transaction{ @database.delete(recall_cue) }
|
21
|
+
return true
|
25
22
|
end
|
26
23
|
|
27
|
-
def
|
28
|
-
list_cues.
|
24
|
+
def has_cue?(recall_cue)
|
25
|
+
list_cues.any?{ |cue| cue == recall_cue }
|
29
26
|
end
|
30
27
|
|
31
28
|
def list_cues
|
32
29
|
@database.transaction { @database.roots }
|
33
30
|
end
|
34
31
|
|
35
|
-
def
|
36
|
-
|
32
|
+
def present?
|
33
|
+
File.exists?(@database.path)
|
34
|
+
end
|
35
|
+
|
36
|
+
def save!
|
37
|
+
@database.transaction{@database.commit}
|
38
|
+
end
|
39
|
+
|
40
|
+
def recall(recall_cue)
|
41
|
+
raise "no entry for cue '#{recall_cue}'" unless has_cue?(recall_cue)
|
42
|
+
@database.transaction { @database[recall_cue] }
|
43
|
+
end
|
44
|
+
|
45
|
+
def size
|
46
|
+
list_cues.size
|
37
47
|
end
|
38
48
|
|
39
49
|
end
|
data/lib/sheldon/sheldon.rb
CHANGED
@@ -1,36 +1,40 @@
|
|
1
1
|
require "fileutils"
|
2
2
|
|
3
3
|
class Sheldon
|
4
|
-
VERSION = "0.
|
4
|
+
VERSION = "0.5.0".freeze
|
5
5
|
attr_reader :brain, :builder
|
6
6
|
|
7
|
-
def initialize(sheldon_data_dir
|
7
|
+
def initialize(sheldon_data_dir)
|
8
8
|
unless Dir.exists?(sheldon_data_dir)
|
9
|
-
raise MissingDataDirectoryException, "
|
9
|
+
raise MissingDataDirectoryException, "Directory #{sheldon_data_dir} does not exist."
|
10
10
|
end
|
11
11
|
|
12
|
-
@brain =
|
13
|
-
@builder =
|
12
|
+
@brain = Brain.new(sheldon_data_dir)
|
13
|
+
@builder = Builder.new
|
14
14
|
end
|
15
15
|
|
16
16
|
def build(abs_learn_path)
|
17
17
|
builder.build(abs_learn_path)
|
18
18
|
end
|
19
19
|
|
20
|
+
def forget(recall_cue)
|
21
|
+
brain.forget(recall_cue)
|
22
|
+
end
|
23
|
+
|
20
24
|
def learn(recall_cue, abs_learn_path)
|
21
25
|
brain.learn(recall_cue, abs_learn_path)
|
22
26
|
end
|
23
27
|
|
24
|
-
def
|
25
|
-
brain.
|
28
|
+
def list_cues
|
29
|
+
brain.list_cues
|
26
30
|
end
|
27
31
|
|
28
|
-
def
|
29
|
-
brain.
|
32
|
+
def recall(recall_cue)
|
33
|
+
brain.recall(recall_cue)
|
30
34
|
end
|
31
35
|
|
32
|
-
def
|
33
|
-
brain.
|
36
|
+
def setup!
|
37
|
+
brain.memory.save!
|
34
38
|
end
|
35
39
|
|
36
40
|
def recalled?(recall_cue)
|
metadata
CHANGED
@@ -1,89 +1,89 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sheldon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Jones
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-04-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ~>
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0.9'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ~>
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0.9'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ~>
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '11.1'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ~>
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '11.1'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ~>
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '3.3'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ~>
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '3.3'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: coveralls
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ~>
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: 0.8.13
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - ~>
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: 0.8.13
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: byebug
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- -
|
73
|
+
- - ~>
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '9.0'
|
76
|
-
- -
|
76
|
+
- - '>='
|
77
77
|
- !ruby/object:Gem::Version
|
78
78
|
version: 9.0.0
|
79
79
|
type: :development
|
80
80
|
prerelease: false
|
81
81
|
version_requirements: !ruby/object:Gem::Requirement
|
82
82
|
requirements:
|
83
|
-
- -
|
83
|
+
- - ~>
|
84
84
|
- !ruby/object:Gem::Version
|
85
85
|
version: '9.0'
|
86
|
-
- -
|
86
|
+
- - '>='
|
87
87
|
- !ruby/object:Gem::Version
|
88
88
|
version: 9.0.0
|
89
89
|
description: Another config and dotfile manager for unix environments
|
@@ -93,16 +93,16 @@ executables:
|
|
93
93
|
extensions: []
|
94
94
|
extra_rdoc_files: []
|
95
95
|
files:
|
96
|
-
- LICENSE
|
97
|
-
- README.md
|
98
|
-
- bin/sheldon
|
99
|
-
- lib/sheldon.rb
|
100
96
|
- lib/sheldon/brain.rb
|
101
97
|
- lib/sheldon/builder.rb
|
102
98
|
- lib/sheldon/exceptions.rb
|
103
99
|
- lib/sheldon/helpers.rb
|
104
100
|
- lib/sheldon/memory.rb
|
105
101
|
- lib/sheldon/sheldon.rb
|
102
|
+
- lib/sheldon.rb
|
103
|
+
- bin/sheldon
|
104
|
+
- LICENSE
|
105
|
+
- README.md
|
106
106
|
homepage: https://github.com/dvjones89/sheldon
|
107
107
|
licenses:
|
108
108
|
- MIT
|
@@ -113,17 +113,17 @@ require_paths:
|
|
113
113
|
- lib
|
114
114
|
required_ruby_version: !ruby/object:Gem::Requirement
|
115
115
|
requirements:
|
116
|
-
- -
|
116
|
+
- - '>='
|
117
117
|
- !ruby/object:Gem::Version
|
118
118
|
version: '0'
|
119
119
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
120
120
|
requirements:
|
121
|
-
- -
|
121
|
+
- - '>='
|
122
122
|
- !ruby/object:Gem::Version
|
123
123
|
version: '0'
|
124
124
|
requirements: []
|
125
125
|
rubyforge_project:
|
126
|
-
rubygems_version: 2.
|
126
|
+
rubygems_version: 2.0.14.1
|
127
127
|
signing_key:
|
128
128
|
specification_version: 4
|
129
129
|
summary: Another config and dotfile manager for unix environments
|