booker 0.3.1 → 0.3.2
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 +10 -12
- data/lib/config.rb +23 -13
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 94d50219879478c9d6762be1e50de304c6cbc5d0
|
4
|
+
data.tar.gz: 768a969566680d92447cc156d5f06df8421590ca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 38be1cdef260f686f731ee9f912b6c16bbd09e50aa9dbeb8ca72d5536faac4ae2c3ec5161c066a99f8a8ef91b3af6ef945b1e1cb449bfbabf63b54467a8feb3b
|
7
|
+
data.tar.gz: 06dd6ff3e6fd121728c7eee4a979fdad519c08e3820dea374d4ea0fcdc6ae581d659d4a8ce6f750b65d020be652eeadb3680ab46dc0050e58f434bc8a62be0fb
|
data/lib/booker.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# parse web's command line args
|
2
2
|
|
3
3
|
|
4
|
-
VERSION = "0.3"
|
4
|
+
VERSION = "0.3.2"
|
5
5
|
|
6
6
|
|
7
7
|
require 'yaml'
|
@@ -37,23 +37,24 @@ class Booker
|
|
37
37
|
parse_opt args if /^-.*/.match(args[0])
|
38
38
|
|
39
39
|
# interpret
|
40
|
-
|
41
|
-
browsearg = args.shift
|
40
|
+
browsearg = args[0]
|
42
41
|
|
43
|
-
if
|
42
|
+
if browsearg.match(/^[0-9]/) # bookmark
|
44
43
|
bm = Bookmarks.new('')
|
45
44
|
url = bm.bookmark_url(browsearg)
|
45
|
+
pexit "Failure:".red + " bookmark #{browsearg} not found", 1 if url.nil?
|
46
46
|
puts 'opening ' + url + '...'
|
47
|
-
system browse
|
47
|
+
system browse << wrap(url)
|
48
48
|
|
49
49
|
elsif domain.match(browsearg) # website
|
50
50
|
puts 'opening ' + browsearg + '...'
|
51
|
-
system browse
|
51
|
+
system browse << wrap(prep(browsearg))
|
52
52
|
|
53
|
-
else
|
53
|
+
else
|
54
|
+
allargs = wrap(args.join(' '))
|
54
55
|
puts 'searching ' + allargs + '...'
|
55
56
|
search = BConfig.new.searcher
|
56
|
-
system browse
|
57
|
+
system browse << wrap(search + allargs)
|
57
58
|
|
58
59
|
end
|
59
60
|
end
|
@@ -124,7 +125,7 @@ class Booker
|
|
124
125
|
if args[0] == "--version" or args[0] == "-v"
|
125
126
|
pexit VERSION, 0
|
126
127
|
end
|
127
|
-
end
|
128
|
+
end # parse opt
|
128
129
|
|
129
130
|
def install(args)
|
130
131
|
target = args.shift
|
@@ -132,13 +133,10 @@ class Booker
|
|
132
133
|
|
133
134
|
if /comp/i.match(target) # completion installation
|
134
135
|
install_completion
|
135
|
-
|
136
136
|
elsif /book/i.match(target) # bookmarks installation
|
137
137
|
install_bookmarks
|
138
|
-
|
139
138
|
elsif /conf/i.match(target) # default config file generation
|
140
139
|
install_config
|
141
|
-
|
142
140
|
else # unknown argument passed into install
|
143
141
|
pexit "Failure: ".red + "unknown installation option (#{target})", 1
|
144
142
|
end
|
data/lib/config.rb
CHANGED
@@ -22,6 +22,7 @@ module Browser
|
|
22
22
|
extend OS
|
23
23
|
def browse
|
24
24
|
if OS.windows?
|
25
|
+
# alternatively, start seems to work
|
25
26
|
'/cygdrive/c/Program\ Files\ \(x86\)/Google/Chrome/Application/chrome.exe '
|
26
27
|
elsif OS.mac?
|
27
28
|
'open -a "Google Chrome" '
|
@@ -51,42 +52,51 @@ end
|
|
51
52
|
|
52
53
|
# high level configuration
|
53
54
|
class BConfig
|
54
|
-
|
55
|
+
VALID = [:searcher, :bookmarks, :browser]
|
56
|
+
HOME = ENV['HOME'].nil?? '/usr/local/' : ENV['HOME']
|
57
|
+
YAMLCONF = HOME + '/.booker.yml'
|
55
58
|
|
56
59
|
def initialize
|
57
60
|
# config defaults (for osx, default chrome profile)
|
58
|
-
|
61
|
+
readyaml = read(YAMLCONF)
|
62
|
+
default_config = {
|
63
|
+
:browser => 'open ',
|
59
64
|
:searcher => "https://duckduckgo.com/?q=",
|
60
|
-
:bookmarks =>
|
65
|
+
:bookmarks => HOME +
|
61
66
|
"/Library/Application Support/Google/Chrome/Profile 1/Bookmarks",
|
62
67
|
}
|
63
68
|
|
64
|
-
# configure
|
65
|
-
@config =
|
69
|
+
# configure w/ yaml config file, if it exists
|
70
|
+
@config = readyaml ? readyaml : default_config
|
66
71
|
|
67
|
-
|
68
|
-
@config.each do |k,v|
|
69
|
-
|
72
|
+
# prune bad config keys
|
73
|
+
@config.each do |k, v|
|
74
|
+
if !VALID.include? k.to_sym
|
75
|
+
puts "Failure:".red + " Bad key found in config file: #{k}"
|
76
|
+
exit 1
|
77
|
+
end
|
70
78
|
end
|
71
79
|
end
|
72
80
|
|
73
81
|
def read(file)
|
74
82
|
begin
|
75
|
-
|
83
|
+
config = YAML::load(IO.read(file))
|
76
84
|
rescue Errno::ENOENT
|
77
85
|
puts "Warning: ".yel +
|
78
86
|
"YAML configuration file couldn't be found. Using defaults."
|
79
87
|
puts "Suggest: ".grn +
|
80
88
|
"web --install config"
|
89
|
+
return false
|
81
90
|
rescue Psych::SyntaxError
|
82
91
|
puts "Warning: ".red +
|
83
92
|
"YAML configuration file contains invalid syntax. Using defaults."
|
93
|
+
return false
|
84
94
|
end
|
85
|
-
|
95
|
+
config
|
86
96
|
end
|
87
97
|
|
88
98
|
def write(k=nil, v=nil)
|
89
|
-
if k.nil?
|
99
|
+
if k.nil? || v.nil?
|
90
100
|
File.open(YAMLCONF, 'w') {|f| f.write(@config.to_yaml) }
|
91
101
|
else
|
92
102
|
@config[k] = v
|
@@ -95,10 +105,10 @@ class BConfig
|
|
95
105
|
end
|
96
106
|
|
97
107
|
def bookmarks
|
98
|
-
@config[
|
108
|
+
@config[:bookmarks]
|
99
109
|
end
|
100
110
|
|
101
111
|
def searcher
|
102
|
-
@config[
|
112
|
+
@config[:searcher]
|
103
113
|
end
|
104
114
|
end
|