noter 0.2.0 → 0.3.0
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/noter +32 -18
- data/lib/noter/version.rb +1 -1
- data/lib/noter/viewer.rb +22 -4
- data/noter.gemspec +1 -0
- data/spec/lib/noter/viewer_spec.rb +35 -8
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 24a405e2ffe8fc73d6315ce36bec44d2a67b621a
|
4
|
+
data.tar.gz: a3603bbc7dbbbf662501c5f69e73f85b3fec538d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4b79b72a1c8a004dcbb7ce8dde204b9402b3a9fc66731d395b750a9d14336a8903c9649f51af7e060cc3a72782abbb033ca9e7a1d1bd065d88efd3b89ba48acf
|
7
|
+
data.tar.gz: 3a7f667891072910ee06345eb365ef4c851da02b1b6fc2d12a859986b060a21968471b8c562f94f5e96dcea9b0046742d48794efcc9aaca098c0f3c3aad50a98
|
data/bin/noter
CHANGED
@@ -5,7 +5,7 @@ require "optparse"
|
|
5
5
|
|
6
6
|
class NoteRunner
|
7
7
|
def initialize
|
8
|
-
@
|
8
|
+
@options = {:paging => true}
|
9
9
|
end
|
10
10
|
|
11
11
|
def run(args)
|
@@ -15,16 +15,16 @@ class NoteRunner
|
|
15
15
|
|
16
16
|
def run_command
|
17
17
|
case @command
|
18
|
-
when :
|
19
|
-
Noter::
|
18
|
+
when :show_file_from_index
|
19
|
+
Noter::Viewer.new(@options).show_file_from_index(@index)
|
20
20
|
when :show_first_lines
|
21
|
-
Noter::Viewer.new(
|
21
|
+
Noter::Viewer.new(@options).show_first_lines(:with_filename => @show_names)
|
22
|
+
when :show_files
|
23
|
+
Noter::Viewer.new(@options).show_files
|
22
24
|
when :create_from_string
|
23
25
|
Noter::FileMaker.new(@message).save_file
|
24
|
-
when :
|
25
|
-
Noter::
|
26
|
-
when :show_file_from_index
|
27
|
-
Noter::Viewer.new(:paging => @paging).show_file_from_index(@index)
|
26
|
+
when :make_from_file
|
27
|
+
Noter::FileMaker.new.make_from_file(@filename)
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
@@ -35,32 +35,46 @@ class NoteRunner
|
|
35
35
|
@filename = filename
|
36
36
|
end
|
37
37
|
|
38
|
+
opts.on("-g", "--grep STRING", "Only show files that contain a specific string") do |grep_string|
|
39
|
+
@options[:grep_string] = grep_string
|
40
|
+
end
|
41
|
+
|
38
42
|
opts.on("-l", "--one-line", "Show first line of each note file") do
|
39
43
|
@command = :show_first_lines
|
40
44
|
end
|
41
45
|
|
46
|
+
opts.on("-m", "--message MESSAGE", "Create a note using the given string") do |message|
|
47
|
+
@command = :create_from_string
|
48
|
+
@message = message
|
49
|
+
end
|
50
|
+
|
42
51
|
opts.on("-n", "--name", "Include names when showing files") do
|
43
52
|
@command = :show_first_lines
|
44
53
|
@show_names = true
|
45
54
|
end
|
46
55
|
|
47
|
-
opts.on("-
|
48
|
-
@
|
49
|
-
|
56
|
+
opts.on("--no-color", "Don't colorize output") do
|
57
|
+
@options[:colorize] = false
|
58
|
+
end
|
59
|
+
|
60
|
+
opts.on("-s", "--search STRING", "Show a file with the given index") do |grep_string|
|
61
|
+
@options[:tail_count] = 100 unless @options[:tail_count]
|
62
|
+
@options[:grep_string] = grep_string
|
63
|
+
@command = :show_files
|
50
64
|
end
|
51
65
|
|
52
66
|
opts.on("-t", "--tail COUNT", "the last n files") do |count|
|
53
|
-
@command = :
|
54
|
-
@
|
67
|
+
@command = :show_files
|
68
|
+
@options[:tail_count] = count
|
55
69
|
end
|
56
70
|
|
57
|
-
opts.on("-
|
58
|
-
@
|
59
|
-
@index = index
|
71
|
+
opts.on("-u", "--unpaged", "Don't page the output") do
|
72
|
+
@options[:paging] = false
|
60
73
|
end
|
61
74
|
|
62
|
-
opts.on("-
|
63
|
-
@
|
75
|
+
opts.on("-v", "--view INDEX", "View a file with the given index") do |index|
|
76
|
+
@command = :show_file_from_index
|
77
|
+
@index = index
|
64
78
|
end
|
65
79
|
end
|
66
80
|
parser.parse!
|
data/lib/noter/version.rb
CHANGED
data/lib/noter/viewer.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require "noter/note_file"
|
2
2
|
require "pager"
|
3
|
+
require "colorize"
|
3
4
|
|
4
5
|
module Noter
|
5
6
|
class Viewer
|
@@ -9,10 +10,23 @@ module Noter
|
|
9
10
|
|
10
11
|
def initialize(options = {})
|
11
12
|
@do_paging = options[:paging].nil? ? true : options[:paging]
|
13
|
+
@do_colors = options[:colorize].nil? ? true : options[:colorize]
|
14
|
+
@grep_string = options[:grep_string]
|
15
|
+
@tail_count = options[:tail_count].nil? ? false : options[:tail_count].to_i
|
12
16
|
end
|
13
17
|
|
14
18
|
def existing_files
|
15
|
-
@existing_files
|
19
|
+
return @existing_files if @existing_files
|
20
|
+
|
21
|
+
if @grep_string
|
22
|
+
@existing_files = `grep -l #{@grep_string} #{NoteFile.dir}/*`.split("\n")
|
23
|
+
else
|
24
|
+
@existing_files = Dir.glob("#{NoteFile.dir}/*")
|
25
|
+
end
|
26
|
+
if @tail_count
|
27
|
+
@existing_files = @existing_files.last(@tail_count)
|
28
|
+
end
|
29
|
+
@existing_files
|
16
30
|
end
|
17
31
|
|
18
32
|
def show_first_lines(options = {})
|
@@ -40,9 +54,13 @@ module Noter
|
|
40
54
|
puts contents
|
41
55
|
end
|
42
56
|
|
43
|
-
def
|
44
|
-
existing_files.
|
45
|
-
|
57
|
+
def show_files
|
58
|
+
existing_files.each do |filename|
|
59
|
+
if @do_colors
|
60
|
+
puts "\n\n#{filename}".colorize(:red)
|
61
|
+
else
|
62
|
+
puts "\n\n#{filename}"
|
63
|
+
end
|
46
64
|
show_file(filename)
|
47
65
|
end
|
48
66
|
end
|
data/noter.gemspec
CHANGED
@@ -21,6 +21,21 @@ module Noter
|
|
21
21
|
it "returns the names of all the existing files" do
|
22
22
|
expect(viewer.existing_files).to eql(%W{#{NoteFile.dir}/2014_09_21_18_20_22.txt #{NoteFile.dir}/2014_09_21_19_20_22.txt})
|
23
23
|
end
|
24
|
+
|
25
|
+
describe "when grepping" do
|
26
|
+
let(:viewer) { Noter::Viewer.new(:grep_string => "foo") }
|
27
|
+
let(:grep_result) { "line 1\nline 2" }
|
28
|
+
|
29
|
+
it "shells out to grep to get matching filenames" do
|
30
|
+
expect(viewer).to receive(:`).with("grep -l foo #{NoteFile.dir}/*").and_return(grep_result)
|
31
|
+
viewer.existing_files
|
32
|
+
end
|
33
|
+
|
34
|
+
it "splits the lines returned by grep" do
|
35
|
+
allow(viewer).to receive(:`).and_return(grep_result)
|
36
|
+
expect(viewer.existing_files).to eql(["line 1", "line 2"])
|
37
|
+
end
|
38
|
+
end
|
24
39
|
end
|
25
40
|
|
26
41
|
describe "#show_first_lines" do
|
@@ -69,18 +84,30 @@ module Noter
|
|
69
84
|
end
|
70
85
|
end
|
71
86
|
|
72
|
-
describe "#
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
87
|
+
describe "#show_files" do
|
88
|
+
describe "without colors" do
|
89
|
+
let(:viewer) { Noter::Viewer.new(:colorize => false, :tail_count => "2") }
|
90
|
+
|
91
|
+
it "puts the last two files" do
|
92
|
+
expect(viewer).to receive(:puts).with("\n\n#{file_1_name}")
|
93
|
+
expect(viewer).to receive(:puts).with(file_1_contents)
|
94
|
+
expect(viewer).to receive(:puts).with("\n\n#{file_2_name}")
|
95
|
+
expect(viewer).to receive(:puts).with(file_2_contents)
|
96
|
+
viewer.show_files
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
describe "with colors" do
|
101
|
+
it "adds color to the filename" do
|
102
|
+
expect(viewer).to receive(:puts).with("\n\n#{file_1_name}".colorize(:red))
|
103
|
+
expect(viewer).to receive(:puts).with("\n\n#{file_2_name}".colorize(:red))
|
104
|
+
viewer.show_files
|
105
|
+
end
|
79
106
|
end
|
80
107
|
|
81
108
|
it "converts string args to int" do
|
82
109
|
expect {
|
83
|
-
viewer.
|
110
|
+
viewer.show_files
|
84
111
|
}.to_not raise_error
|
85
112
|
end
|
86
113
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: noter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeff Roush
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-10-
|
11
|
+
date: 2014-10-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -122,6 +122,20 @@ dependencies:
|
|
122
122
|
- - "~>"
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '1.0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: colorize
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :runtime
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
125
139
|
description: 'Inspired (read: stolen) from the ''journal'' and ''jrnl'' python progrsm.
|
126
140
|
At the moment, those are more developed; use them instead of this.'
|
127
141
|
email:
|