booker 0.3 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/booker.rb +79 -69
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dda11b55cafd0dde5ad282177e0313752a70f2e6
|
4
|
+
data.tar.gz: 023838be5b1e5c47ca2dc2c2e919a916c797d77b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4635c3785c478a30e61820b47d08e9d2bcc2d3bf8f5c406d03ee3aca58eca0b6ea266dfc7990e39c91e05a7847e92745c6dddfcc1dd84b0db37f7434f058f295
|
7
|
+
data.tar.gz: 1cb46435f22998e10ebd17446b7de3752f82f9becc2df6ee0b6a405fff9fb63094727ced289af7b92bbd2a8af99c6d368e783ab4c604db278959f36e8c291d68
|
data/lib/booker.rb
CHANGED
@@ -20,15 +20,15 @@ class Booker
|
|
20
20
|
parse args
|
21
21
|
end
|
22
22
|
|
23
|
-
def helper
|
24
|
-
pexit HELP_BANNER, 1
|
25
|
-
end
|
26
|
-
|
27
23
|
def pexit(msg, sig)
|
28
24
|
puts msg
|
29
25
|
exit sig
|
30
26
|
end
|
31
27
|
|
28
|
+
def helper
|
29
|
+
pexit HELP_BANNER, 0
|
30
|
+
end
|
31
|
+
|
32
32
|
def parse(args)
|
33
33
|
# no args given, show help
|
34
34
|
helper if args.none?
|
@@ -37,26 +37,24 @@ class Booker
|
|
37
37
|
parse_opt args if /^-.*/.match(args[0])
|
38
38
|
|
39
39
|
# interpret
|
40
|
-
|
41
|
-
|
42
|
-
browsearg = args.shift
|
40
|
+
allargs = wrap(args.join(' '))
|
41
|
+
browsearg = args.shift
|
43
42
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
43
|
+
if /[0-9]/.match(browsearg[0]) # bookmark
|
44
|
+
bm = Bookmarks.new('')
|
45
|
+
url = bm.bookmark_url(browsearg)
|
46
|
+
puts 'opening ' + url + '...'
|
47
|
+
system browse, wrap(url)
|
49
48
|
|
50
|
-
|
51
|
-
|
52
|
-
|
49
|
+
elsif domain.match(browsearg) # website
|
50
|
+
puts 'opening ' + browsearg + '...'
|
51
|
+
system browse, wrap(prep(browsearg))
|
53
52
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
53
|
+
else # just search for these arguments
|
54
|
+
puts 'searching ' + allargs + '...'
|
55
|
+
search = BConfig.new.searcher
|
56
|
+
system browse, search, allargs
|
58
57
|
|
59
|
-
end
|
60
58
|
end
|
61
59
|
end
|
62
60
|
|
@@ -75,10 +73,10 @@ class Booker
|
|
75
73
|
if id
|
76
74
|
url = bm.bookmark_url(id)
|
77
75
|
puts 'opening ' + url + '...'
|
78
|
-
|
76
|
+
system browse << wrap(url)
|
79
77
|
exit 0
|
80
78
|
else
|
81
|
-
pexit '
|
79
|
+
pexit 'Error: '.red +
|
82
80
|
'web --bookmark expects bookmark id', 1
|
83
81
|
end
|
84
82
|
end
|
@@ -98,7 +96,7 @@ class Booker
|
|
98
96
|
if args.length > 0
|
99
97
|
install(args)
|
100
98
|
else
|
101
|
-
pexit '
|
99
|
+
pexit 'Error: '.red +
|
102
100
|
"web --install expects arguments: [completion, bookmarks, config]", 1
|
103
101
|
end
|
104
102
|
end
|
@@ -117,7 +115,7 @@ class Booker
|
|
117
115
|
else
|
118
116
|
puts 'searching ' + allargs + '...'
|
119
117
|
search = BConfig.new.searcher
|
120
|
-
|
118
|
+
system browse << search << allargs
|
121
119
|
exit 0
|
122
120
|
end
|
123
121
|
end
|
@@ -133,62 +131,74 @@ class Booker
|
|
133
131
|
exit 0 if target.nil?
|
134
132
|
|
135
133
|
if /comp/i.match(target) # completion installation
|
136
|
-
|
137
|
-
begin
|
138
|
-
fpath = `zsh -c 'echo $fpath'`.split(' ')
|
139
|
-
rescue
|
140
|
-
pexit "Failure: ".red +
|
141
|
-
"zsh is probably not installed, could not find $fpath", 1
|
142
|
-
end
|
143
|
-
# determine where to install completion function
|
144
|
-
fpath.each do |fp|
|
145
|
-
begin
|
146
|
-
File.open(fp + "/_web", 'w') {|f| f.write(COMPLETION) }
|
147
|
-
system "zsh -c 'autoload -U _web'"
|
148
|
-
puts "Success: ".grn +
|
149
|
-
"installed zsh autocompletion in #{fp}"
|
150
|
-
break # if this works, don't try anymore
|
151
|
-
rescue
|
152
|
-
puts "Failure: ".red +
|
153
|
-
"could not write ZSH completion _web script to $fpath"
|
154
|
-
end
|
155
|
-
end
|
134
|
+
install_completion
|
156
135
|
|
157
136
|
elsif /book/i.match(target) # bookmarks installation
|
158
|
-
|
159
|
-
puts 'searching for chrome bookmarks... (takes some time)'
|
160
|
-
begin
|
161
|
-
bms = []
|
162
|
-
Find.find(ENV["HOME"]) do |path|
|
163
|
-
bms << path if /chrom.*bookmarks/i.match path
|
164
|
-
end
|
165
|
-
puts 'select your bookmarks file: '
|
166
|
-
bms.each_with_index{|bm, i| puts i.to_s.grn + " - " + bm }
|
167
|
-
selected = bms[gets.chomp.to_i]
|
168
|
-
puts 'Selected: '.yel + selected
|
169
|
-
BConfig.new.write('bookmarks', selected)
|
170
|
-
puts "Success: ".grn +
|
171
|
-
"config file updated with your bookmarks"
|
172
|
-
rescue
|
173
|
-
pexit "Failure: ".red +
|
174
|
-
"could not add bookmarks to config file ~/.booker", 1
|
175
|
-
end
|
137
|
+
install_bookmarks
|
176
138
|
|
177
139
|
elsif /conf/i.match(target) # default config file generation
|
140
|
+
install_config
|
141
|
+
|
142
|
+
else # unknown argument passed into install
|
143
|
+
pexit "Failure: ".red + "unknown installation option (#{target})", 1
|
144
|
+
end
|
145
|
+
|
146
|
+
install(args) # recurse til done
|
147
|
+
end
|
148
|
+
|
149
|
+
def install_completion
|
150
|
+
# check if zsh is even installed for this user
|
151
|
+
begin
|
152
|
+
fpath = `zsh -c 'echo $fpath'`.split(' ')
|
153
|
+
rescue
|
154
|
+
pexit "Failure: ".red +
|
155
|
+
"zsh is probably not installed, could not find $fpath", 1
|
156
|
+
end
|
157
|
+
|
158
|
+
# determine where to install completion function
|
159
|
+
fpath.each do |fp|
|
178
160
|
begin
|
179
|
-
|
161
|
+
File.open(fp + "/_web", 'w') {|f| f.write(COMPLETION) }
|
162
|
+
system "zsh -c 'autoload -U _web'"
|
180
163
|
puts "Success: ".grn +
|
181
|
-
"
|
164
|
+
"installed zsh autocompletion in #{fp}"
|
165
|
+
break # if this works, don't try anymore
|
182
166
|
rescue
|
183
|
-
|
184
|
-
"could not write
|
167
|
+
puts "Failure: ".red +
|
168
|
+
"could not write ZSH completion _web script to $fpath (#{fp})"
|
185
169
|
end
|
170
|
+
end
|
171
|
+
end
|
186
172
|
|
187
|
-
|
173
|
+
def install_bookmarks
|
174
|
+
# locate bookmarks file, show user, write to config?
|
175
|
+
puts 'searching for chrome bookmarks... (takes some time)'
|
176
|
+
begin
|
177
|
+
bms = []
|
178
|
+
Find.find(ENV["HOME"]) do |path|
|
179
|
+
bms << path if /chrom.*bookmarks/i.match path
|
180
|
+
end
|
181
|
+
puts 'select your bookmarks file: '
|
182
|
+
bms.each_with_index{|bm, i| puts i.to_s.grn + " - " + bm }
|
183
|
+
selected = bms[gets.chomp.to_i]
|
184
|
+
puts 'Selected: '.yel + selected
|
185
|
+
BConfig.new.write('bookmarks', selected)
|
186
|
+
puts "Success: ".grn +
|
187
|
+
"config file updated with your bookmarks"
|
188
|
+
rescue
|
188
189
|
pexit "Failure: ".red +
|
189
|
-
"
|
190
|
+
"could not add bookmarks to config file ~/.booker", 1
|
190
191
|
end
|
192
|
+
end
|
191
193
|
|
192
|
-
|
194
|
+
def install_config
|
195
|
+
begin
|
196
|
+
BConfig.new.write
|
197
|
+
puts "Success: ".grn +
|
198
|
+
"example config file written to ~/.booker"
|
199
|
+
rescue
|
200
|
+
pexit "Failure: ".red +
|
201
|
+
"could not write example config file to ~/.booker", 1
|
202
|
+
end
|
193
203
|
end
|
194
204
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: booker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeremy Warner
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-11-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ruby-terminfo
|