epitools 0.5.100 → 0.5.103
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/epitools/clitools.rb +23 -0
- data/lib/epitools/core_ext/enumerable.rb +1 -1
- data/lib/epitools/core_ext/file.rb +26 -1
- data/lib/epitools/minimal.rb +32 -27
- data/lib/epitools/path.rb +7 -8
- data/spec/clitools_spec.rb +5 -0
- data/spec/core_ext_spec.rb +18 -0
- 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: 37053f6a5bb1b1406914ce14114703107679b60f
|
4
|
+
data.tar.gz: 7a309d8da2d15f2f73021680cb0de08846089db3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6008b6abf95ac50f0ce55974b0378a3a03eee78f94d9a71967b75b482b1bdd9b99993d702dbb432c55da127fdafcb12b42e30a674d734d8baa610116254f69e6
|
7
|
+
data.tar.gz: b0ba59178f118c8d857fe7d853ba47d224c74806ac5be870e6d7203cabcc5a588615e0913d7a7e703b0a9748875e7f003a28b7438ba02ac9eab6b08323e907ea
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.5.
|
1
|
+
0.5.103
|
data/lib/epitools/clitools.rb
CHANGED
@@ -207,3 +207,26 @@ def which(*bins)
|
|
207
207
|
end
|
208
208
|
nil
|
209
209
|
end
|
210
|
+
|
211
|
+
|
212
|
+
#
|
213
|
+
# Executes notify-send to create a desktop notification on the user's desktop
|
214
|
+
#
|
215
|
+
# Note: the 'icon' argument is the path to an image file
|
216
|
+
#
|
217
|
+
def notify_send(title, body=nil, icon: nil, time: 5)
|
218
|
+
$stderr.puts "* #{title}"
|
219
|
+
$stderr.puts " |_ #{body}" if body
|
220
|
+
|
221
|
+
time_in_ms = time * 1000
|
222
|
+
|
223
|
+
cmd = ["notify-send"]
|
224
|
+
cmd << "--expire-time=#{time_in_ms}"
|
225
|
+
cmd << "--app-name=#{Process.argv0}"
|
226
|
+
cmd << "--icon=#{icon}" if icon
|
227
|
+
cmd << CGI.escapeHTML(title)
|
228
|
+
cmd << CGI.escapeHTML(body) if body
|
229
|
+
|
230
|
+
fork { system *cmd }
|
231
|
+
end
|
232
|
+
|
@@ -374,7 +374,7 @@ module Enumerable
|
|
374
374
|
end
|
375
375
|
|
376
376
|
#
|
377
|
-
# Reverse zip (aligns the ends of two arrays, and
|
377
|
+
# Reverse zip (aligns the ends of two arrays, and zips them from right to left)
|
378
378
|
#
|
379
379
|
# eg:
|
380
380
|
# >> [5,39].rzip([:hours, :mins, :secs])
|
@@ -98,10 +98,32 @@ class File
|
|
98
98
|
data
|
99
99
|
end
|
100
100
|
|
101
|
+
#
|
102
|
+
# Scan through the file until `string` is found, and set the IO's +pos+ to the first character of the matched string.
|
103
|
+
#
|
104
|
+
def seek_to(string, blocksize=512)
|
105
|
+
raise "Error: blocksize must be at least as large as the string" if string.size < blocksize
|
106
|
+
|
107
|
+
loop do
|
108
|
+
data = read(blocksize)
|
109
|
+
|
110
|
+
if index = data.index(string)
|
111
|
+
seek(-(data.size - index), IO::SEEK_CUR)
|
112
|
+
break
|
113
|
+
elsif eof?
|
114
|
+
break
|
115
|
+
else
|
116
|
+
seek(-(string.size - 1), IO::SEEK_CUR)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
101
121
|
#
|
102
122
|
# Scan backwards in the file until `string` is found, and set the IO's +pos+ to the first character after the matched string.
|
103
|
-
#
|
123
|
+
#
|
104
124
|
def seek_backwards_to(string, blocksize=512, rindex_end=-1)
|
125
|
+
raise "Error: blocksize must be at least as large as the string" if string.size < blocksize
|
126
|
+
|
105
127
|
loop do
|
106
128
|
data = reverse_read(blocksize)
|
107
129
|
|
@@ -110,8 +132,11 @@ class File
|
|
110
132
|
break
|
111
133
|
elsif pos == 0
|
112
134
|
break
|
135
|
+
else
|
136
|
+
seek(string.size - 1, IO::SEEK_CUR)
|
113
137
|
end
|
114
138
|
end
|
115
139
|
end
|
140
|
+
alias_method :reverse_seek_to, :seek_backwards_to
|
116
141
|
|
117
142
|
end
|
data/lib/epitools/minimal.rb
CHANGED
@@ -262,33 +262,38 @@ end
|
|
262
262
|
|
263
263
|
####################################################################
|
264
264
|
|
265
|
-
class << ARGV
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
265
|
+
# class << ARGV
|
266
|
+
|
267
|
+
# def opts
|
268
|
+
# @opts, @args ||= partition { |arg| arg[/^--?\w{1,2}/].nil? }
|
269
|
+
# end
|
270
|
+
|
271
|
+
# def args
|
272
|
+
# @args ? @args : opts && @args
|
273
|
+
# end
|
274
|
+
|
275
|
+
# def paths
|
276
|
+
# map(&:to_Path)
|
277
|
+
# end
|
278
|
+
|
279
|
+
# def paths_R
|
280
|
+
# recursive_proc = proc do |paths|
|
281
|
+
# paths.map { |path| path.dir? ? the_expander.(path.ls_R) : path }
|
282
|
+
# end
|
283
|
+
|
284
|
+
# recursive_proc.(paths)
|
285
|
+
# end
|
286
|
+
# alias_method :recursive_paths, :paths_R
|
287
|
+
|
288
|
+
# def regexes(escaped: true, case_sensitive: false)
|
289
|
+
# if case_sensitive
|
290
|
+
# map { |arg| /#{escaped ? Regexp.escape(arg) : arg}/ } # NO 'i'
|
291
|
+
# else
|
292
|
+
# map { |arg| /#{escaped ? Regexp.escape(arg) : arg}/i }
|
293
|
+
# end
|
294
|
+
# end
|
295
|
+
|
296
|
+
# end
|
292
297
|
|
293
298
|
####################################################################
|
294
299
|
|
data/lib/epitools/path.rb
CHANGED
@@ -125,14 +125,13 @@ class Path
|
|
125
125
|
def initialize(newpath, hints={})
|
126
126
|
send("path=", newpath, hints)
|
127
127
|
|
128
|
-
#
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
end
|
128
|
+
# if hints[:unlink_when_garbage_collected]
|
129
|
+
# backup_path = path.dup
|
130
|
+
# puts "unlinking #{backup_path} after gc!"
|
131
|
+
# ObjectSpace.define_finalizer self do |object_id|
|
132
|
+
# File.unlink backup_path
|
133
|
+
# end
|
134
|
+
# end
|
136
135
|
end
|
137
136
|
|
138
137
|
def initialize_copy(other)
|
data/spec/clitools_spec.rb
CHANGED
data/spec/core_ext_spec.rb
CHANGED
@@ -1022,6 +1022,24 @@ end
|
|
1022
1022
|
|
1023
1023
|
describe File do
|
1024
1024
|
|
1025
|
+
it "seeks_to" do
|
1026
|
+
tmp = Path.tmp
|
1027
|
+
tmp << "012345hello7890"
|
1028
|
+
f = open(tmp)
|
1029
|
+
|
1030
|
+
f.seek_to("hell", 4)
|
1031
|
+
|
1032
|
+
f.pos.should == 6
|
1033
|
+
f.read(4).should == "hell"
|
1034
|
+
|
1035
|
+
f.seek(-1, IO::SEEK_END)
|
1036
|
+
|
1037
|
+
f.seek_backwards_to("hell", 5)
|
1038
|
+
|
1039
|
+
f.pos.should == 10
|
1040
|
+
f.read(4).should == "o789"
|
1041
|
+
end
|
1042
|
+
|
1025
1043
|
it "reverse_eaches" do
|
1026
1044
|
tmp = Path.tmp
|
1027
1045
|
tmp << "hi\nthere\neveryone!\n"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: epitools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.103
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- epitron
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-02-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|