buf 0.0.5 → 0.0.6

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/buf.rb +79 -48
  3. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4d11c4937144a30cfe4280f534bac6bb8e867ea3
4
- data.tar.gz: 66a0ce9bbf038b4741df325d871458ee8fd6c606
3
+ metadata.gz: 3c6ac32c2f67d961d34a7b97d3f8ea38739d1cfa
4
+ data.tar.gz: 27198fa908101a3421fdc8a1c1ee3d02b984113c
5
5
  SHA512:
6
- metadata.gz: 8c7552e69f7bfe8fb3d8c672cd0e7abe6f112b54a811677ed3d863d6df842e636eedac6a98c475f7acb0fff9e73bab31cfe9ecb1b3cb9da42311adabe8844841
7
- data.tar.gz: 19afa57fbecd03f37322f95c3a6125f56d02cb176487237e2153808a35ef4ade6742b2a34a8a9edc84008a6a480d3eccff6f7c4c7d4b007550c249e51bf4d8d7
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
- # no I just write directly to the config file. Just do that
19
- # and I just write directly to that and um. well.
20
- # I want to be able to control it with git so I need
21
- # to be able to put it in a folder
22
- # so the config file will be there at
23
- # .bufrc
24
- # if there is no ~/.bufrc I will create one
25
- # and the default path will be in ~/
26
- # for the buffile and the archive file
27
- # yes. so it will be
28
- # buf.txt and buf.archive.txt
29
- # so basically just read from the config file
30
- # and look for a buffile and archive file in that spot
31
- # and if there is one, read it, and if there isn't, create one
32
- # and create the folder and read from it. that's pretty simple. to change the buffile
33
- # or archive file you manually modify .bufrc.
34
- # then I think I'll be done with buf
35
- @buffile = "/users/rocker/buf/lib/foo.txt"
36
- @archivefile = "/users/rocker/buf/lib/foo.txt.archive"
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.5
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-18 00:00:00.000000000 Z
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: still working on it
45
+ summary: It is working.
46
46
  test_files: []