booker 0.3 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/booker.rb +79 -69
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5567e3732287e8680b5d69750b5a7ad29d292398
4
- data.tar.gz: 030ad3b1bbcd9dd616a8350c514dfb4433f9fcef
3
+ metadata.gz: dda11b55cafd0dde5ad282177e0313752a70f2e6
4
+ data.tar.gz: 023838be5b1e5c47ca2dc2c2e919a916c797d77b
5
5
  SHA512:
6
- metadata.gz: 9a0272734819dc107596283fc56dc580e29359e7f96e35a0e1d92e2a84c4acebf24ff0dafe7d45fc8ecbef3fda7ae80496bd78d38233732f5a7fed4f6e94042b
7
- data.tar.gz: 183bb981b94176d4f38783b9e54d426be8fb59c316672aaa3e7d2d34067558bc2e9d7803e184d16f97f304037b5de193575840aac20333cd1544a7060abc8c49
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
- while args do
41
- allargs = "'" + args.join(' ') + "'"
42
- browsearg = args.shift
40
+ allargs = wrap(args.join(' '))
41
+ browsearg = args.shift
43
42
 
44
- if /[0-9]/.match(browsearg[0]) # bookmark
45
- bm = Bookmarks.new('')
46
- url = bm.bookmark_url(browsearg)
47
- puts 'opening ' + url + '...'
48
- exec browse << wrap(url)
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
- elsif domain.match(browsearg) # website
51
- puts 'opening ' + browsearg + '...'
52
- exec browse << wrap(prep(browsearg))
49
+ elsif domain.match(browsearg) # website
50
+ puts 'opening ' + browsearg + '...'
51
+ system browse, wrap(prep(browsearg))
53
52
 
54
- else # just search for these arguments
55
- puts 'searching ' + allargs + '...'
56
- search = BConfig.new.searcher
57
- exec browse << search << allargs
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
- exec browse << wrap(url)
76
+ system browse << wrap(url)
79
77
  exit 0
80
78
  else
81
- pexit ' Error: '.red +
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 ' Error: '.red +
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
- exec browse << search << allargs
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
- # check if zsh is even installed for this user
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
- # locate bookmarks file, show user, write to config?
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
- BConfig.new.write
161
+ File.open(fp + "/_web", 'w') {|f| f.write(COMPLETION) }
162
+ system "zsh -c 'autoload -U _web'"
180
163
  puts "Success: ".grn +
181
- "example config file written to ~/.booker"
164
+ "installed zsh autocompletion in #{fp}"
165
+ break # if this works, don't try anymore
182
166
  rescue
183
- pexit "Failure: ".red +
184
- "could not write example config file to ~/.booker", 1
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
- else # unknown argument passed into install
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
- "unknown installation option (#{target})", 1
190
+ "could not add bookmarks to config file ~/.booker", 1
190
191
  end
192
+ end
191
193
 
192
- install(args) # recurse til done
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: '0.3'
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-10-20 00:00:00.000000000 Z
11
+ date: 2015-11-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby-terminfo