buf 0.0.6 → 0.0.7
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/bin/buf +80 -29
- 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: 00d2cbdf8dd5d3b366144f1aa47d7b265036932a
|
4
|
+
data.tar.gz: 5dc864056d912fefa90c0bba617a5fc5c601ef54
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3b577d382eb281c2dbc33602d375e2be4c15948910421b9d82f7cb4c96bde41378134829a7b9ab1961237abd19e539a4440595aa2da5300bdff85db6abde9ba2
|
7
|
+
data.tar.gz: a8d59de6a395a22d2d9aa4568a4bc881aebd42c00434cf9ed1306ed2110ba0e7f7364900aed165d86ea5bcff8fd5af75d49acd419c94924d5a0488d1e3267a70
|
data/bin/buf
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
#
|
2
3
|
|
3
4
|
# rubygems
|
4
5
|
require 'rubygems'
|
@@ -12,8 +13,84 @@ class Buf < Thor
|
|
12
13
|
|
13
14
|
def initialize(*args)
|
14
15
|
super
|
15
|
-
|
16
|
-
|
16
|
+
dotfile = File.expand_path('~/.bufrc')
|
17
|
+
check_dotfile(dotfile)
|
18
|
+
read_dotfile(dotfile)
|
19
|
+
check_files
|
20
|
+
end
|
21
|
+
|
22
|
+
no_commands do
|
23
|
+
def check_files
|
24
|
+
unless File.file?(@buffile)
|
25
|
+
unless File.directory?(File.dirname(@buffile))
|
26
|
+
FileUtils.mkdir_p(File.dirname(@buffile))
|
27
|
+
end
|
28
|
+
File.open(@buffile, 'w') do
|
29
|
+
end
|
30
|
+
end
|
31
|
+
unless File.file?(@archivefile)
|
32
|
+
unless File.directory?(File.dirname(@archivefile))
|
33
|
+
FileUtils.mkdir_p(File.dirname(@archivefile))
|
34
|
+
end
|
35
|
+
File.open(@archivefile, 'w') do
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def check_dotfile(dotfile)
|
41
|
+
unless File.file?(dotfile)
|
42
|
+
File.open(dotfile, 'a') do |f|
|
43
|
+
f << "set buffile = ~/buffile.txt\n"
|
44
|
+
f << "set archivefile = ~/buffile.txt.archive"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def read_dotfile(dotfile)
|
50
|
+
File.foreach(dotfile).with_index do |line, line_num|
|
51
|
+
line = line.chomp
|
52
|
+
line_array = line.split
|
53
|
+
if (line[0] != '#')
|
54
|
+
if (line_array.length == 4 &&
|
55
|
+
line_array[0] == 'set' &&
|
56
|
+
line_array[2] == '=' &&
|
57
|
+
(line_array[1] == 'buffile' || line_array[1] == 'archivefile'))
|
58
|
+
if line_array[1] == 'buffile'
|
59
|
+
@buffile = File.expand_path(line_array[3])
|
60
|
+
else
|
61
|
+
@archivefile = File.expand_path(line_array[3])
|
62
|
+
end
|
63
|
+
else
|
64
|
+
raise "Error in .bufrc line #{line_num}"
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def cull
|
71
|
+
now = Time.now
|
72
|
+
buf = File.open(@buffile, "r")
|
73
|
+
temp = Tempfile.new("tempbaby")
|
74
|
+
|
75
|
+
buf.each do |line|
|
76
|
+
date = (line.split)[-1]
|
77
|
+
date = Time.new(date[0..3], date[4..5], date[6..7], date[9..10], date[11..12], date[13..14])
|
78
|
+
if ((date <=> now) == -1)
|
79
|
+
# write to archive
|
80
|
+
File.open(@archivefile, "r") do |origArch|
|
81
|
+
File.unlink(@archivefile)
|
82
|
+
File.open(@archivefile, "w") do |newArch|
|
83
|
+
newArch.write(line)
|
84
|
+
newArch.write(origArch.read)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
else
|
88
|
+
temp << line
|
89
|
+
end
|
90
|
+
end
|
91
|
+
temp.close
|
92
|
+
FileUtils.mv(temp.path, @buffile)
|
93
|
+
end
|
17
94
|
end
|
18
95
|
|
19
96
|
desc "wr NOTE TIME", "appends note to buffile with the expiration time appended"
|
@@ -28,33 +105,7 @@ class Buf < Thor
|
|
28
105
|
end
|
29
106
|
end
|
30
107
|
end
|
31
|
-
|
32
|
-
desc "cull", "moves expired notes to archive file"
|
33
|
-
def cull
|
34
|
-
now = Time.now
|
35
|
-
buf = File.open(@buffile, "r")
|
36
|
-
temp = Tempfile.new("tempbaby")
|
37
|
-
|
38
|
-
buf.each do |line|
|
39
|
-
date = (line.split)[-1]
|
40
|
-
date = Time.new(date[0..3], date[4..5], date[6..7], date[9..10], date[11..12], date[13..14])
|
41
|
-
if ((date <=> now) == -1)
|
42
|
-
# write to archive
|
43
|
-
File.open(@archivefile, "r") do |origArch|
|
44
|
-
File.unlink(@archivefile)
|
45
|
-
File.open(@archivefile, "w") do |newArch|
|
46
|
-
newArch.write(line)
|
47
|
-
newArch.write(origArch.read)
|
48
|
-
end
|
49
|
-
end
|
50
|
-
else
|
51
|
-
temp << line
|
52
|
-
end
|
53
|
-
end
|
54
|
-
temp.close
|
55
|
-
FileUtils.mv(temp.path, @buffile)
|
56
|
-
end
|
57
|
-
|
108
|
+
|
58
109
|
desc "echo", "prints unexpired notes"
|
59
110
|
def echo
|
60
111
|
cull
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: buf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Douglas Lamb
|
@@ -42,5 +42,5 @@ rubyforge_project:
|
|
42
42
|
rubygems_version: 2.4.5
|
43
43
|
signing_key:
|
44
44
|
specification_version: 4
|
45
|
-
summary: It is working.
|
45
|
+
summary: It is working. with 0.0.6 I had forgotten to add the new cli to /bin
|
46
46
|
test_files: []
|