cnote 0.1.3 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0f576ae8756a70983786ca2c5fd60e057103e520
4
- data.tar.gz: 4f8d882001c3402892ee357a925e04b491bd2a52
3
+ metadata.gz: 4b85c6a02284c2120ce8daaf4582f3bcba9b54bc
4
+ data.tar.gz: 7b0c3e88353e7f46e295f6232253eb98d0b6008a
5
5
  SHA512:
6
- metadata.gz: d50be2e44a608d3f58cbba5d861e16f34086319abbea7e541cf0e08864af389f83fdb8f88e7dd87db1551f228132f3073d9304017220c27998a66b55c9d39dfe
7
- data.tar.gz: 862a4fe135058318ca4c4014b5bbd9eb8ac4fd03ef11787f8d83f66508d832eef57c1249045fefd01b1fba17c348b2c773d46c6f21e5ce9103aee18ba422a542
6
+ metadata.gz: 98bda843720a6789a57e1c0d075f4e29e9aace16f8ea97a0572999f58ad0db28d52f6bf110cec241bd629d13f367b31a1049b7c6c7e42f57a28bd5f097c8ec5f
7
+ data.tar.gz: f3eea2df867c25f9414ad2dbd7ac7f8a4d40ed5bba9aa2251e914092eb25d89b0110ce51659cd4d8983b001dcf9dd53eed12c6defcca25f03d820577814b37f3
data/README.md CHANGED
@@ -3,6 +3,14 @@
3
3
 
4
4
  CNote is my personal system for managing notes. I wanted something snappy and lightweight that would let me search, tag and edit a folder full of markdown files using just my keyboard and some `vim`-ish single-letter commands.
5
5
 
6
+ ## Changelog
7
+
8
+ ### 0.2.0
9
+ - Added `config` command to adjust configuration within CNote. Try: `config set prompt >>>` or `config get editor`, or even just `config` to edit the file directly. Current config properties are `prompt`, `editor`, and `note_path`.
10
+
11
+ ### 0.1.3 and lower
12
+ - Trial and error gem publishing-related fixes.
13
+
6
14
  ## Installation
7
15
 
8
16
  First of all, make sure you have a recent version of Ruby installed (including RubyGems). I'm using 2.4.0. Then run:
data/cnote.gemspec CHANGED
@@ -26,4 +26,5 @@ Gem::Specification.new do |spec|
26
26
  spec.add_development_dependency "rspec", "~> 3.0"
27
27
 
28
28
  spec.add_runtime_dependency "colorize", "~> 0.8.1"
29
+ spec.add_runtime_dependency "awesome_print"
29
30
  end
data/lib/cnote/config.rb CHANGED
@@ -1,28 +1,22 @@
1
1
  require "yaml"
2
2
  require "fileutils"
3
+ require "ap"
3
4
 
4
5
  class Config
5
- attr_reader :note_path
6
+ attr_reader :note_path, :path
7
+ attr_writer :prompt, :editor
6
8
 
7
9
  def initialize(path)
8
- path = File.expand_path path
10
+ @path = File.expand_path(path)
9
11
 
10
- if !File.exists? path
12
+ if !File.exists?(@path)
11
13
  puts "Welcome, new user!"
12
14
 
13
15
  @note_path = get_note_path
14
-
15
- File.open(path, "w") do |file|
16
- file.write(YAML.dump(to_hash))
17
- end
18
-
16
+ save
19
17
  puts "Okay, we're ready to go!"
20
18
  else
21
- conf = YAML.load(File.read(path))
22
-
23
- @note_path = conf["note_path"]
24
- @editor = conf["editor"]
25
- @cursor = conf["prompt"]
19
+ load
26
20
  end
27
21
  end
28
22
 
@@ -57,13 +51,52 @@ class Config
57
51
  @editor || ENV["EDITOR"]
58
52
  end
59
53
 
60
- def cursor
61
- @cursor || ">"
54
+ def prompt
55
+ @prompt || ">"
56
+ end
57
+
58
+ def set(key, val)
59
+ case key.downcase
60
+ when 'editor'
61
+ @editor = val
62
+ when 'prompt'
63
+ @prompt = val
64
+ end
65
+ save
66
+ end
67
+
68
+ def get(key)
69
+ case key.downcase
70
+ when 'editor'
71
+ editor
72
+ when 'prompt'
73
+ prompt
74
+ end
75
+ end
76
+
77
+ def save
78
+ File.open(@path, "w") do |file|
79
+ file.write(YAML.dump(to_hash))
80
+ end
81
+ end
82
+
83
+ def load
84
+ conf = YAML.load(File.read(@path))
85
+
86
+ @note_path = conf["note_path"]
87
+ @editor = conf["editor"]
88
+ @prompt = conf["prompt"]
89
+ end
90
+
91
+ def print
92
+ ap to_hash
62
93
  end
63
94
 
64
95
  def to_hash
65
- {
66
- "note_path" => @note_path
67
- }
96
+ hash = Hash.new
97
+ hash["note_path"] = @note_path if @note_path
98
+ hash["editor"] = @editor if @editor
99
+ hash["prompt"] = @prompt if @prompt
100
+ return hash
68
101
  end
69
102
  end
data/lib/cnote/notes.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require "colorize"
2
2
  require "fileutils"
3
3
  require "time"
4
+ require "ap"
4
5
  require "cnote/note"
5
6
 
6
7
  class Notes
@@ -16,7 +17,7 @@ class Notes
16
17
 
17
18
  def await_command(message = nil)
18
19
  puts message if message
19
- print "#{@config.cursor} ".magenta
20
+ print "#{@config.prompt} ".magenta
20
21
  input = STDIN.gets.chomp
21
22
 
22
23
  # Strip and process
@@ -44,6 +45,8 @@ class Notes
44
45
  list
45
46
  when "help", "h"
46
47
  help
48
+ when "config", "conf"
49
+ config(params)
47
50
  when "quit", "exit", "close", "q"
48
51
  exit
49
52
  else
@@ -123,19 +126,26 @@ class Notes
123
126
  else
124
127
  return
125
128
  end
129
+ else
130
+ # Make sure the directory actually exists.
131
+ FileUtils.mkdir_p(File.join(@config.note_path, rel_path))
126
132
  end
127
133
 
128
134
  system "#{@config.editor} '#{full_path}'"
129
135
 
130
- note = Note.new(full_path)
131
- note.add_tags(tags) if tags.length > 0
132
- note.created = Time.new
133
- note.update
136
+ if File.exists?(full_path)
137
+ note = Note.new(full_path)
138
+ note.add_tags(tags) if tags.length > 0
139
+ note.created = Time.new
140
+ note.update
134
141
 
135
- @notes << Note.new(full_path)
142
+ @notes << Note.new(full_path)
136
143
 
137
- print_list("Created", [note])
138
- @filtered = [note]
144
+ print_list("Created", [note])
145
+ @filtered = [note]
146
+ else
147
+ puts "Scrapped the blank note..."
148
+ end
139
149
  else
140
150
  puts "Please enter a filename as the first parameter"
141
151
  end
@@ -172,6 +182,10 @@ class Notes
172
182
  end
173
183
 
174
184
  def peek(params)
185
+ if params&.first&.downcase == 'config'
186
+ return @config.print
187
+ end
188
+
175
189
  note = @filtered[params.first.to_i - 1]
176
190
  if note
177
191
  lines = note.content.lines
@@ -220,10 +234,42 @@ class Notes
220
234
  puts "Removed #{params.length - 1} tag#{"s" if params.length != 2} from #{notes.length} note#{"s" if notes.length != 1}."
221
235
  end
222
236
 
237
+ def config(params = [])
238
+ if params.length == 0
239
+ system "#{@config.editor} #{@config.path}"
240
+ @config.load
241
+ return
242
+ end
243
+
244
+ action, key, *value = params
245
+ value = value.join(" ")
246
+
247
+ if action == "get"
248
+ if key
249
+ puts "#{key}: \"#{@config.get(key)}\""
250
+ else
251
+ @config.print
252
+ end
253
+ elsif action == "set"
254
+ if key
255
+ if value
256
+ puts "Config: #{key} changed from '#{@config.get(key)}' to '#{value}'"
257
+ @config.set(key, value)
258
+ else
259
+ puts "Can't set a key to a value if no value is given."
260
+ end
261
+ else
262
+ puts "Can't set a key if one wasn't given."
263
+ end
264
+ else
265
+ puts "Invalid action: #{action}"
266
+ end
267
+ end
268
+
223
269
  def help
224
270
  puts
225
271
  puts "Enter a command with the structure:"
226
- puts " #{@config.cursor} action parameter(s)"
272
+ puts " #{@config.prompt} action parameter(s)"
227
273
  puts
228
274
  puts "Actions:"
229
275
  puts " - #{"new".bold.white} #{"filename".italic}"
@@ -234,6 +280,7 @@ class Notes
234
280
  puts " - #{"untag".bold.white} #{"note_number".italic}"
235
281
  puts " - #{"search".bold.white} #{"search_term".italic}"
236
282
  puts " - #{"list".bold.white}"
283
+ puts " - #{"config".bold.white} #{"(set/get)".italic} #{"key".italic} [#{"value".italic}]"
237
284
  puts " - #{"exit".bold.white}"
238
285
  puts " - #{"help".bold.white}"
239
286
  puts
data/lib/cnote/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Cnote
2
- VERSION = "0.1.3"
2
+ VERSION = "0.2.0"
3
3
  end
data/lib/cnote.rb CHANGED
@@ -4,7 +4,10 @@ require "cnote/notes"
4
4
  require "cnote/version"
5
5
 
6
6
  config = Config.new("~/.cnote.yaml")
7
-
8
- # Start REPL
9
7
  notes = Notes.new(config)
10
- notes.await_command("\nWelcome to CNote! Type #{'help'.white} or #{'h'.white} to see a list of available commands.")
8
+
9
+ if ARGV[0]
10
+ notes.run_command(ARGV.shift, ARGV)
11
+ else
12
+ notes.await_command("\nWelcome to CNote! Type #{'help'.white} or #{'h'.white} to see a list of available commands.")
13
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cnote
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tony McCoy
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-09-12 00:00:00.000000000 Z
11
+ date: 2017-09-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: 0.8.1
69
+ - !ruby/object:Gem::Dependency
70
+ name: awesome_print
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
69
83
  description: Take notes with a fast and efficient CLI
70
84
  email:
71
85
  - tony@ratwizard.io