buf 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/buf.rb +79 -48
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3c6ac32c2f67d961d34a7b97d3f8ea38739d1cfa
|
4
|
+
data.tar.gz: 27198fa908101a3421fdc8a1c1ee3d02b984113c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 08f7cc96941891bddb62b2d24b704ec53129df7e18dd660b39293db89badbeff3cd4f1a13fb7945d6e49f53ebd2460f6ac193103af2408cf5dd72729f965457d
|
7
|
+
data.tar.gz: e952ccae6a9d6bbccd322e262808cd0ebcf6a7e6695be7b77eac650c2913cc3f59a1851005d76aff1f002636088df4ba57bd450e667dc58782b1afd0a7f38f6d
|
data/lib/buf.rb
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
#
|
3
|
-
# next thing i'm doing is making this thing work with two dotfiles instead of my foo.txt
|
4
|
-
# and foo.txt.archive
|
5
3
|
|
6
4
|
# rubygems
|
7
5
|
require 'rubygems'
|
@@ -15,25 +13,84 @@ class Buf < Thor
|
|
15
13
|
|
16
14
|
def initialize(*args)
|
17
15
|
super
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
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
|
37
94
|
end
|
38
95
|
|
39
96
|
desc "wr NOTE TIME", "appends note to buffile with the expiration time appended"
|
@@ -48,33 +105,7 @@ class Buf < Thor
|
|
48
105
|
end
|
49
106
|
end
|
50
107
|
end
|
51
|
-
|
52
|
-
desc "cull", "moves expired notes to archive file"
|
53
|
-
def cull
|
54
|
-
now = Time.now
|
55
|
-
buf = File.open(@buffile, "r")
|
56
|
-
temp = Tempfile.new("tempbaby")
|
57
|
-
|
58
|
-
buf.each do |line|
|
59
|
-
date = (line.split)[-1]
|
60
|
-
date = Time.new(date[0..3], date[4..5], date[6..7], date[9..10], date[11..12], date[13..14])
|
61
|
-
if ((date <=> now) == -1)
|
62
|
-
# write to archive
|
63
|
-
File.open(@archivefile, "r") do |origArch|
|
64
|
-
File.unlink(@archivefile)
|
65
|
-
File.open(@archivefile, "w") do |newArch|
|
66
|
-
newArch.write(line)
|
67
|
-
newArch.write(origArch.read)
|
68
|
-
end
|
69
|
-
end
|
70
|
-
else
|
71
|
-
temp << line
|
72
|
-
end
|
73
|
-
end
|
74
|
-
temp.close
|
75
|
-
FileUtils.mv(temp.path, @buffile)
|
76
|
-
end
|
77
|
-
|
108
|
+
|
78
109
|
desc "echo", "prints unexpired notes"
|
79
110
|
def echo
|
80
111
|
cull
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Douglas Lamb
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-05-
|
11
|
+
date: 2015-05-20 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A dead simple short-term memory aid
|
14
14
|
email: douglaslamb@douglaslamb.com
|
@@ -42,5 +42,5 @@ rubyforge_project:
|
|
42
42
|
rubygems_version: 2.4.5
|
43
43
|
signing_key:
|
44
44
|
specification_version: 4
|
45
|
-
summary:
|
45
|
+
summary: It is working.
|
46
46
|
test_files: []
|