booker 2.2.0 → 2.2.1
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/lib/booker/cli.rb +9 -5
- data/lib/booker/config.rb +41 -7
- data/lib/booker/installer.rb +4 -3
- data/lib/booker/parsers.rb +13 -8
- data/lib/booker/tlds.txt +1436 -0
- data/lib/booker/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 775c1f7390fbe5b793703bba1be907504ed571adb2ce6bf97a67a6957dc0478a
|
|
4
|
+
data.tar.gz: 5f17c3c1348b41124626260004fd182ac8f90e2229da168942e95ed0059acb8a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: dfe0cc75af9fd5c273ac460fc182148260ff8c3073df75865d8f852179677ccc94bea38890d97648f18411360518517fc8099181fd2aaeab6faab505e55d0d38
|
|
7
|
+
data.tar.gz: f1870b789f13c20a873f6fc3bd27e55fdb00e47cf29d1a756aa578d1a7266d53eeb39acb7247d2f17b426218149384887db152b60d1a9e451d7627ba1036acf9
|
data/lib/booker/cli.rb
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
# parse booker's command line args and act on them
|
|
4
4
|
|
|
5
|
+
require "shellwords"
|
|
6
|
+
|
|
5
7
|
require_relative "output"
|
|
6
8
|
|
|
7
9
|
using Booker::Colors
|
|
@@ -37,7 +39,7 @@ module Booker
|
|
|
37
39
|
# every argument being a url means they all came from tab completion,
|
|
38
40
|
# which inserts one per bookmark - open the lot. one non-url word makes
|
|
39
41
|
# the whole line a search, so a phrase containing a domain still is one
|
|
40
|
-
if other_args.all? { |arg|
|
|
42
|
+
if other_args.all? { |arg| site?(arg) }
|
|
41
43
|
other_args.each do |site|
|
|
42
44
|
puts "opening website: ".grn + site
|
|
43
45
|
openweb(prep(site))
|
|
@@ -116,12 +118,14 @@ module Booker
|
|
|
116
118
|
end
|
|
117
119
|
|
|
118
120
|
def openweb(url)
|
|
119
|
-
#
|
|
120
|
-
#
|
|
121
|
-
|
|
121
|
+
# the url goes to the browser as its own argument, without a shell, so
|
|
122
|
+
# parentheses and ampersands in it mean nothing. the command itself is
|
|
123
|
+
# split with Shellwords, like :picker, so a configured `open -a Firefox`
|
|
124
|
+
# is a command and two flags rather than one program by that whole name
|
|
125
|
+
browser_cmd = Shellwords.split(browse)
|
|
122
126
|
|
|
123
127
|
# Redirect stdout/stderr to suppress GTK warnings
|
|
124
|
-
success = system(browser_cmd, url, out: File::NULL, err: File::NULL)
|
|
128
|
+
success = system(*browser_cmd, url, out: File::NULL, err: File::NULL)
|
|
125
129
|
|
|
126
130
|
unless success
|
|
127
131
|
# system reports a missing binary as nil rather than false, but the
|
data/lib/booker/config.rb
CHANGED
|
@@ -19,9 +19,13 @@ module Booker
|
|
|
19
19
|
def self.linux? = !(windows? || mac?)
|
|
20
20
|
end
|
|
21
21
|
|
|
22
|
-
#
|
|
22
|
+
# the command that opens a link: the config's :browser if it names one,
|
|
23
|
+
# otherwise whatever opens a url on this platform
|
|
23
24
|
module Browser
|
|
24
25
|
def browse
|
|
26
|
+
configured = Config.default.browser
|
|
27
|
+
return configured if configured
|
|
28
|
+
|
|
25
29
|
if OS.windows?
|
|
26
30
|
# alternatively, start seems to work - probably check if powershell v cygwin?
|
|
27
31
|
'/cygdrive/c/Program\ Files\ \(x86\)/Google/Chrome/Application/chrome.exe '
|
|
@@ -39,12 +43,29 @@ module Booker
|
|
|
39
43
|
# read the rule from here rather than spelling it out twice and drifting
|
|
40
44
|
SCHEME = /[a-z][a-z0-9+.-]*:\/\//i
|
|
41
45
|
|
|
42
|
-
#
|
|
43
|
-
#
|
|
44
|
-
#
|
|
45
|
-
# (io|com|net|org|...) list sent .dev and .ai off to the search engine
|
|
46
|
+
# the shape of a website rather than a search term: an explicit scheme, or
|
|
47
|
+
# a bare host with a dot and an alphabetic tld, captured so #site? can check
|
|
48
|
+
# it is a real one
|
|
46
49
|
def domain
|
|
47
|
-
%r{\A(?:#{SCHEME}\S+|(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z]{2,}(?::\d+)?(?:[/?#]\S*)?)\z}io
|
|
50
|
+
%r{\A(?:#{SCHEME}\S+|(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+(?<tld>[a-z]{2,})(?::\d+)?(?:[/?#]\S*)?)\z}io
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# should this argument be opened rather than searched for? anything with a
|
|
54
|
+
# scheme is a url. a bare host also has to end in a tld on IANA's list,
|
|
55
|
+
# all of them - completion inserts real bookmark urls, and a hand picked
|
|
56
|
+
# (io|com|net|org|...) once sent .dev and .ai to the search engine - but
|
|
57
|
+
# the shape alone said vue.js and node.js were websites
|
|
58
|
+
def site?(arg)
|
|
59
|
+
match = domain.match(arg) or return false
|
|
60
|
+
match[:tld].nil? || Browser.tlds.include?(match[:tld].downcase)
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
# IANA's list, refreshed with `just tlds`. read on first use rather than at
|
|
64
|
+
# load, since completion subshells never ask
|
|
65
|
+
def self.tlds
|
|
66
|
+
@tlds ||= File.readlines(File.join(__dir__, "tlds.txt"), chomp: true)
|
|
67
|
+
.reject { |line| line.start_with?("#") }
|
|
68
|
+
.to_set
|
|
48
69
|
end
|
|
49
70
|
|
|
50
71
|
# only a bare host needs a scheme invented for it. testing for "http" alone
|
|
@@ -83,8 +104,9 @@ module Booker
|
|
|
83
104
|
# the yaml file if there is one, and only work out the defaults when
|
|
84
105
|
# there is not: discovery walks every chrome profile directory to answer
|
|
85
106
|
# a question the config file has already answered
|
|
107
|
+
# no :browser here: #browse works it out per platform, and writing one
|
|
108
|
+
# down would pin this machine's answer into the file
|
|
86
109
|
@config = read(YAMLCONF) || {
|
|
87
|
-
browser: "open ",
|
|
88
110
|
searcher: "https://google.com/search?q=",
|
|
89
111
|
bookmarks: detect_default_bookmarks
|
|
90
112
|
}
|
|
@@ -158,6 +180,18 @@ module Booker
|
|
|
158
180
|
|
|
159
181
|
def searcher = @config[:searcher]
|
|
160
182
|
|
|
183
|
+
# the command that opens links, flags and all. nil means "work it out from
|
|
184
|
+
# the platform" - see Browser#browse
|
|
185
|
+
def browser
|
|
186
|
+
configured = @config[:browser].to_s
|
|
187
|
+
# the built-in defaults once wrote "open " on every platform, so a linux
|
|
188
|
+
# or windows config made by --install holds the macOS command. it never
|
|
189
|
+
# worked there, and is not a choice anybody made
|
|
190
|
+
return nil if configured.strip.empty? || (configured.strip == "open" && !OS.mac?)
|
|
191
|
+
|
|
192
|
+
configured
|
|
193
|
+
end
|
|
194
|
+
|
|
161
195
|
# the finder command with its flags, split with Shellwords rather than
|
|
162
196
|
# handed to a shell. nil means "auto detect fzf", which is why #write leaves
|
|
163
197
|
# it out of the defaults: #initialize exits on keys it does not know, so a
|
data/lib/booker/installer.rb
CHANGED
|
@@ -270,8 +270,7 @@ module Booker
|
|
|
270
270
|
bms = Sources.discover
|
|
271
271
|
|
|
272
272
|
if bms.empty? # no bookmarks found
|
|
273
|
-
|
|
274
|
-
raise
|
|
273
|
+
raise "No browser bookmarks file could be found."
|
|
275
274
|
elsif bms.length == 1
|
|
276
275
|
# Auto-select if only one source found
|
|
277
276
|
selected = bms.first
|
|
@@ -288,7 +287,9 @@ module Booker
|
|
|
288
287
|
puts (i + 1).to_s.grn + " - " + label + " " + path
|
|
289
288
|
end
|
|
290
289
|
|
|
291
|
-
|
|
290
|
+
# $stdin, not Kernel#gets: that reads ARGF, which opens the install
|
|
291
|
+
# targets still left in ARGV (`bookmarks`) as files
|
|
292
|
+
input = $stdin.gets
|
|
292
293
|
raise "No input provided" if input.nil?
|
|
293
294
|
|
|
294
295
|
# to_i alone read any typo as 0 - all sources - and a negative number
|
data/lib/booker/parsers.rb
CHANGED
|
@@ -126,15 +126,20 @@ module Booker
|
|
|
126
126
|
return
|
|
127
127
|
end
|
|
128
128
|
|
|
129
|
-
#
|
|
130
|
-
#
|
|
131
|
-
#
|
|
129
|
+
# a running firefox holds the database locked, so read a copy. it also
|
|
130
|
+
# keeps it in WAL mode: recent bookmarks live in places.sqlite-wal until
|
|
131
|
+
# a checkpoint, and sqlite only finds a log named after the database
|
|
132
|
+
# beside it. so the copy is all three files under the same basename, in
|
|
133
|
+
# a directory mktmpdir removes when the block ends
|
|
132
134
|
if firefox_running?
|
|
133
|
-
require "
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
FileUtils.cp(@file_path,
|
|
137
|
-
|
|
135
|
+
require "tmpdir"
|
|
136
|
+
Dir.mktmpdir("booker") do |dir|
|
|
137
|
+
copy = File.join(dir, "places.sqlite")
|
|
138
|
+
FileUtils.cp(@file_path, copy)
|
|
139
|
+
%w[-wal -shm].each do |log|
|
|
140
|
+
FileUtils.cp(@file_path + log, copy + log) if File.exist?(@file_path + log)
|
|
141
|
+
end
|
|
142
|
+
query_places(copy)
|
|
138
143
|
end
|
|
139
144
|
else
|
|
140
145
|
query_places(@file_path)
|