booker 0.2.2 → 0.3
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.rb +11 -10
- data/lib/bookmarks.rb +30 -23
- data/lib/config.rb +1 -1
- metadata +25 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5567e3732287e8680b5d69750b5a7ad29d292398
|
4
|
+
data.tar.gz: 030ad3b1bbcd9dd616a8350c514dfb4433f9fcef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9a0272734819dc107596283fc56dc580e29359e7f96e35a0e1d92e2a84c4acebf24ff0dafe7d45fc8ecbef3fda7ae80496bd78d38233732f5a7fed4f6e94042b
|
7
|
+
data.tar.gz: 183bb981b94176d4f38783b9e54d426be8fb59c316672aaa3e7d2d34067558bc2e9d7803e184d16f97f304037b5de193575840aac20333cd1544a7060abc8c49
|
data/lib/booker.rb
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
# parse web's command line args
|
2
2
|
|
3
3
|
|
4
|
-
VERSION = "0.
|
4
|
+
VERSION = "0.3"
|
5
5
|
|
6
6
|
|
7
7
|
require 'yaml'
|
8
8
|
require 'find'
|
9
9
|
require 'json'
|
10
|
+
require 'terminfo'
|
10
11
|
require_relative 'bookmarks'
|
11
12
|
require_relative 'config'
|
12
13
|
require_relative 'consts'
|
@@ -143,15 +144,15 @@ class Booker
|
|
143
144
|
fpath.each do |fp|
|
144
145
|
begin
|
145
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}"
|
146
150
|
break # if this works, don't try anymore
|
147
151
|
rescue
|
148
152
|
puts "Failure: ".red +
|
149
153
|
"could not write ZSH completion _web script to $fpath"
|
150
154
|
end
|
151
155
|
end
|
152
|
-
exec "zsh -c 'autoload -U _web'"
|
153
|
-
puts "Success: ".grn +
|
154
|
-
"installed zsh autocompletion in #{fpath}"
|
155
156
|
|
156
157
|
elsif /book/i.match(target) # bookmarks installation
|
157
158
|
# locate bookmarks file, show user, write to config?
|
@@ -169,18 +170,18 @@ class Booker
|
|
169
170
|
puts "Success: ".grn +
|
170
171
|
"config file updated with your bookmarks"
|
171
172
|
rescue
|
172
|
-
|
173
|
-
"could not add bookmarks to config file ~/.booker"
|
173
|
+
pexit "Failure: ".red +
|
174
|
+
"could not add bookmarks to config file ~/.booker", 1
|
174
175
|
end
|
175
176
|
|
176
|
-
elsif /
|
177
|
+
elsif /conf/i.match(target) # default config file generation
|
177
178
|
begin
|
178
179
|
BConfig.new.write
|
179
180
|
puts "Success: ".grn +
|
180
|
-
"config file written to ~/.booker"
|
181
|
+
"example config file written to ~/.booker"
|
181
182
|
rescue
|
182
|
-
|
183
|
-
"could not write config file ~/.booker"
|
183
|
+
pexit "Failure: ".red +
|
184
|
+
"could not write example config file to ~/.booker", 1
|
184
185
|
end
|
185
186
|
|
186
187
|
else # unknown argument passed into install
|
data/lib/bookmarks.rb
CHANGED
@@ -1,10 +1,14 @@
|
|
1
1
|
# grab/parse bookmarks from json file on computer
|
2
2
|
|
3
3
|
|
4
|
-
|
4
|
+
# get int number of columns in half of screen
|
5
|
+
TERMWIDTH = (TermInfo.screen_size[1]/2).floor
|
5
6
|
|
7
|
+
# compl. color codes space
|
8
|
+
CODEWIDTH = 16
|
6
9
|
|
7
|
-
|
10
|
+
|
11
|
+
# add some colors, windowing methods
|
8
12
|
class String
|
9
13
|
def window(width)
|
10
14
|
if self.length >= width
|
@@ -14,6 +18,7 @@ class String
|
|
14
18
|
end
|
15
19
|
end
|
16
20
|
|
21
|
+
# thx danhassin
|
17
22
|
def colorize(color, mod)
|
18
23
|
"\033[#{mod};#{color};49m#{self}\033[0;0m"
|
19
24
|
end
|
@@ -47,33 +52,35 @@ class Bookmarks
|
|
47
52
|
parse
|
48
53
|
end
|
49
54
|
|
50
|
-
|
51
|
-
# output for zsh
|
55
|
+
# output for zsh autocompetion, print out id, title and cleaned url
|
52
56
|
def autocomplete
|
53
57
|
@allurls.each do |url|
|
54
|
-
|
55
|
-
|
56
|
-
name.gsub!(/\-+/, '-')
|
57
|
-
name.gsub!(/ /,'')
|
58
|
-
name = name.window(TERMWIDTH)
|
59
|
-
|
60
|
-
# remove strange things from any linkurls
|
61
|
-
link = url.url.gsub(/[,'"&?].*/, '')
|
62
|
-
link.gsub!(/.*:\/+/,'')
|
63
|
-
link.gsub!(/ /,'')
|
64
|
-
link = link[0..TERMWIDTH]
|
65
|
-
|
66
|
-
# print out title and cleaned url, for autocompetion
|
58
|
+
name = clean_name(url)
|
59
|
+
link = clean_link(url)
|
67
60
|
puts url.id + ":" + name + ":" + link
|
68
61
|
end
|
69
62
|
end
|
70
63
|
|
64
|
+
# clean title for completion, delete anything not allowed in linktitle
|
65
|
+
def clean_name(url)
|
66
|
+
name = url.folder + ' |' + url.title.gsub(/[^a-z0-9\-\/_ ]/i, '')
|
67
|
+
name.gsub!(/\-+/, '-')
|
68
|
+
name.gsub!(/[ ]+/,' ')
|
69
|
+
name = name.window(TERMWIDTH)
|
70
|
+
end
|
71
|
+
|
72
|
+
# clean link for completion, remove strange things from any linkurls
|
73
|
+
def clean_link(url)
|
74
|
+
link = url.url.gsub(/[,'"&?].*/, '')
|
75
|
+
link.gsub!(/.*:\/+/,'')
|
76
|
+
link.gsub!(/ /,'')
|
77
|
+
link = link[0..TERMWIDTH-CODEWIDTH] # need space for term. color codes
|
78
|
+
end
|
79
|
+
|
71
80
|
# get link (from id number)
|
72
81
|
def bookmark_url(id)
|
73
82
|
@allurls.each do |url|
|
74
|
-
if id == url.id
|
75
|
-
return url.url
|
76
|
-
end
|
83
|
+
return url.url if id == url.id
|
77
84
|
end
|
78
85
|
end
|
79
86
|
|
@@ -113,8 +120,8 @@ end # close bookmarks class
|
|
113
120
|
# for recursively parsing bookmarks
|
114
121
|
class Folder
|
115
122
|
include Enumerable
|
116
|
-
def initialize(title='
|
117
|
-
@title = title.gsub(/[
|
123
|
+
def initialize(title='|', json)
|
124
|
+
@title = title.gsub(/[:,'"]/, '-').downcase
|
118
125
|
@json = json
|
119
126
|
end
|
120
127
|
|
@@ -127,7 +134,7 @@ end
|
|
127
134
|
# clean bookmark title, set attrs
|
128
135
|
class Bookmark
|
129
136
|
def initialize(f, t, u, id)
|
130
|
-
@title = t.gsub(/[:
|
137
|
+
@title = t.gsub(/[:'"+]/, ' ').downcase
|
131
138
|
@folder = f
|
132
139
|
@url = u
|
133
140
|
@id = id
|
data/lib/config.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,35 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: booker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: '0.3'
|
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-
|
11
|
+
date: 2015-10-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: ruby-terminfo
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.1'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 0.1.1
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0.1'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 0.1.1
|
13
33
|
- !ruby/object:Gem::Dependency
|
14
34
|
name: json
|
15
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -73,9 +93,9 @@ licenses:
|
|
73
93
|
metadata: {}
|
74
94
|
post_install_message: |2
|
75
95
|
Thank you for installing booker!
|
76
|
-
To
|
77
|
-
To add zsh completion,
|
78
|
-
To see more help,
|
96
|
+
To find your bookmarks, run `web -i bookmarks`
|
97
|
+
To add zsh completion, run `web -i completion`
|
98
|
+
To see more help, run `web --help`
|
79
99
|
rdoc_options: []
|
80
100
|
require_paths:
|
81
101
|
- lib
|