til_cli 0.0.1
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 +7 -0
- data/.gitignore +15 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +31 -0
- data/Rakefile +2 -0
- data/bin/til +5 -0
- data/lib/til/cli.rb +83 -0
- data/lib/til/directory.rb +37 -0
- data/lib/til/note.rb +40 -0
- data/lib/til/note_deleter.rb +27 -0
- data/lib/til/note_editor.rb +24 -0
- data/lib/til/note_finder.rb +21 -0
- data/lib/til/note_list.rb +66 -0
- data/lib/til/note_writer.rb +57 -0
- data/lib/til/settings.rb +19 -0
- data/lib/til/version.rb +3 -0
- data/lib/til.rb +164 -0
- data/til.gemspec +25 -0
- metadata +134 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 53b2c9d656469cff4398375a0aac7f97d236a242
|
4
|
+
data.tar.gz: 7155110b28132c3e3df0d753bc591eace76ace2a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0f30305429c78b30f9ae5c8db6cbe5d2becb90a510104243571a43a41d02e978be96c5c79aa254720125b09385875110305af6db409c6408d20bfd7ec143391d
|
7
|
+
data.tar.gz: 6eed2b836570ebacecfbec8cb8112f02f34a4ca71a5afdbde29d89a71ab5ebba01e71933431402cfadf44a28d25dd469489cb37bb9e43b85a530c7a7904e1d3b
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Kevin
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# Til
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'til'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install til
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
TODO: Write usage instructions here
|
24
|
+
|
25
|
+
## Contributing
|
26
|
+
|
27
|
+
1. Fork it ( https://github.com/[my-github-username]/til/fork )
|
28
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
29
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
30
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
31
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/bin/til
ADDED
data/lib/til/cli.rb
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
require 'thor'
|
2
|
+
require 'colorize'
|
3
|
+
require 'fileutils'
|
4
|
+
require 'date'
|
5
|
+
require 'json'
|
6
|
+
|
7
|
+
module Til
|
8
|
+
|
9
|
+
|
10
|
+
class Cli < Thor
|
11
|
+
desc "new SUBJECT \"TITLE\"", "Generate a new note with TITLE about SUBJECT. TITLE should be quoted and shell metacharacters escaped."
|
12
|
+
def new(subject, title)
|
13
|
+
Til.new_note(subject, title)
|
14
|
+
end
|
15
|
+
|
16
|
+
desc "ls [SUBJECT]", "List all notes [on SUBJECT]"
|
17
|
+
def ls(subject = nil)
|
18
|
+
if subject
|
19
|
+
Til.list_notes_in(subject)
|
20
|
+
else
|
21
|
+
Til.list_all_notes
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
desc "subjects", "List all subjects"
|
26
|
+
def subjects
|
27
|
+
Til.list_subjects :bullet_points
|
28
|
+
end
|
29
|
+
|
30
|
+
desc "pwd", "Print the path of your TIL working directory"
|
31
|
+
def pwd
|
32
|
+
Til.print_working_directory
|
33
|
+
end
|
34
|
+
|
35
|
+
desc "last [QUANTITY]", "Print [QUANTITY] most recent note[s]"
|
36
|
+
def last(quantity=1)
|
37
|
+
Til.print_most_recent_note quantity.to_i
|
38
|
+
end
|
39
|
+
|
40
|
+
desc "open", "Open TIL working directory"
|
41
|
+
def open
|
42
|
+
Til.open_working_directory
|
43
|
+
end
|
44
|
+
|
45
|
+
desc "cat [SUBJECT]", "Print all notes [on SUBJECT]"
|
46
|
+
def cat(subject=nil)
|
47
|
+
if subject
|
48
|
+
Til.print_all_notes_in(subject)
|
49
|
+
else
|
50
|
+
Til.print_all_notes
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
desc "edit [SEARCH TERM]", "Edit file that matches search for [SEARCH TERM]."
|
55
|
+
long_desc "`--last` flag"
|
56
|
+
option :last, type: :boolean
|
57
|
+
def edit(keyword="")
|
58
|
+
Til.edit_file(keyword, options)
|
59
|
+
end
|
60
|
+
|
61
|
+
desc "git COMMAND", "Run Git COMMAND in TIL directory"
|
62
|
+
def git(*args)
|
63
|
+
Til.run_git_command(*args)
|
64
|
+
end
|
65
|
+
|
66
|
+
|
67
|
+
desc "grep COMMAND", "Run grep COMMAND in TIL directory"
|
68
|
+
def grep(*args)
|
69
|
+
Til.run_grep_command(*args)
|
70
|
+
end
|
71
|
+
|
72
|
+
|
73
|
+
desc "ag COMMAND", "Run Silver Searcher COMMAND in TIL directory"
|
74
|
+
def ag(*args)
|
75
|
+
Til.run_ag_command(*args)
|
76
|
+
end
|
77
|
+
|
78
|
+
desc "rm [SEARCH TERM]", "Remove a file matching the search term. Prompts for confirmation."
|
79
|
+
def rm(keyword)
|
80
|
+
Til.remove_file(keyword)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'til/note'
|
2
|
+
|
3
|
+
module Til
|
4
|
+
class Directory
|
5
|
+
attr_reader :path
|
6
|
+
|
7
|
+
def initialize(subject=nil)
|
8
|
+
if subject
|
9
|
+
@path = DIRECTORY + "/#{subject}/*.md"
|
10
|
+
else
|
11
|
+
@path = DIRECTORY + "/**/*.md"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.root
|
16
|
+
self.new
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.for(subject)
|
20
|
+
self.new(subject)
|
21
|
+
end
|
22
|
+
|
23
|
+
def notes
|
24
|
+
note_list = NoteList.new
|
25
|
+
note_paths.each do |note_path|
|
26
|
+
note_list.push Note.new(note_path)
|
27
|
+
end
|
28
|
+
note_list
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def note_paths
|
34
|
+
Dir.glob(path)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/lib/til/note.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
module Til
|
2
|
+
class Note
|
3
|
+
attr_accessor :path
|
4
|
+
def initialize path
|
5
|
+
@path = path
|
6
|
+
end
|
7
|
+
|
8
|
+
def mtime
|
9
|
+
File.mtime(path)
|
10
|
+
end
|
11
|
+
|
12
|
+
def subject
|
13
|
+
/\/([^\/]+)\/[^\/]+$/.match(path)[1]
|
14
|
+
end
|
15
|
+
|
16
|
+
def pretty_printed_mtime
|
17
|
+
if date_modified == Date.today
|
18
|
+
"today"
|
19
|
+
elsif date_modified == (Date.today - 1)
|
20
|
+
"yesterday"
|
21
|
+
elsif date_modified > (Date.today - 6)
|
22
|
+
mtime.strftime("%A")
|
23
|
+
else
|
24
|
+
mtime.strftime("%b. %-d, %Y")
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def title
|
29
|
+
content[0].gsub("# ","").chomp
|
30
|
+
end
|
31
|
+
|
32
|
+
def content
|
33
|
+
IO.readlines(path)
|
34
|
+
end
|
35
|
+
|
36
|
+
def date_modified
|
37
|
+
@date_modified ||= mtime.to_date
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Til
|
2
|
+
class NoteDeleter
|
3
|
+
include Thor::Base
|
4
|
+
include Thor::Actions
|
5
|
+
attr_reader :note
|
6
|
+
|
7
|
+
def initialize(note)
|
8
|
+
@note = note
|
9
|
+
end
|
10
|
+
|
11
|
+
def delete
|
12
|
+
begin
|
13
|
+
choice = ask("Really delete \"#{note.title.bold}\" (in #{note.subject.bold})? (y/n)")
|
14
|
+
if (choice == "y") || (choice == "yes")
|
15
|
+
File.delete(note.path)
|
16
|
+
puts "\"#{note.title.bold}\" deleted.".green
|
17
|
+
else
|
18
|
+
puts "\"#{note.title.bold}\" not deleted.".red
|
19
|
+
end
|
20
|
+
rescue Interrupt
|
21
|
+
warn "\nAborted!"
|
22
|
+
abort
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# require 'github-markdown-preview' #!! seems to be slowing things down a lot if placed in til.rb
|
2
|
+
|
3
|
+
module Til
|
4
|
+
class NoteEditor
|
5
|
+
attr_reader :path
|
6
|
+
|
7
|
+
def initialize(note)
|
8
|
+
@path = note.path
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.open(note)
|
12
|
+
self.new(note)
|
13
|
+
end
|
14
|
+
|
15
|
+
def edit
|
16
|
+
# preview = GithubMarkdownPreview::HtmlPreview.new(path)
|
17
|
+
# preview.watch
|
18
|
+
# system("open", preview.preview_file)
|
19
|
+
system(ENV["EDITOR"] || "vim", path)
|
20
|
+
# preview.end_watch
|
21
|
+
# preview.delete
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Til
|
2
|
+
class NoteFinder < Thor
|
3
|
+
include Thor::Actions
|
4
|
+
|
5
|
+
attr_reader :search_term
|
6
|
+
|
7
|
+
def initialize(search_term)
|
8
|
+
@search_term = search_term
|
9
|
+
@matches = NoteList.new
|
10
|
+
Directory.root.notes.each do |note|
|
11
|
+
if note.title.include?(keyword)
|
12
|
+
@matches.push note
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.find(search_term)
|
18
|
+
self.new(search_term)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
module Til
|
2
|
+
class NoteList
|
3
|
+
include Thor::Base
|
4
|
+
include Thor::Actions
|
5
|
+
attr_accessor :notes
|
6
|
+
|
7
|
+
def initialize(notes=Array.new)
|
8
|
+
@notes = notes
|
9
|
+
end
|
10
|
+
|
11
|
+
def sort_by_modified_time
|
12
|
+
notes.sort { |a, b| b.mtime <=> a.mtime }
|
13
|
+
end
|
14
|
+
|
15
|
+
def most_recent
|
16
|
+
notes.sort { |a, b| b.mtime <=> a.mtime }.fetch(0)
|
17
|
+
end
|
18
|
+
|
19
|
+
def filter
|
20
|
+
if notes.length == 1
|
21
|
+
notes.first
|
22
|
+
else
|
23
|
+
notes.each_with_index do |note, index|
|
24
|
+
puts "#{index+1}) #{note.title.bold} (#{note.subject})"
|
25
|
+
end
|
26
|
+
|
27
|
+
begin
|
28
|
+
choice = ask("Choice: ").to_i
|
29
|
+
rescue Interrupt
|
30
|
+
warn "\nAborted!"
|
31
|
+
abort
|
32
|
+
end
|
33
|
+
|
34
|
+
notes.fetch(choice-1) do
|
35
|
+
puts "Invalid choice!"
|
36
|
+
abort
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def method_missing(m, *args, &block)
|
42
|
+
notes.send(m, *args, &block)
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
# def push arg
|
47
|
+
# self.notes.send(:push, arg)
|
48
|
+
# end
|
49
|
+
# def each &block
|
50
|
+
# self.notes.send(:each, &block)
|
51
|
+
# end
|
52
|
+
# def each_with_index &block
|
53
|
+
# self.notes.send(:each_with_index, &block)
|
54
|
+
# end
|
55
|
+
# def empty?
|
56
|
+
# self.notes.send(:empty?)
|
57
|
+
# end
|
58
|
+
# def length
|
59
|
+
# self.notes.send(:length)
|
60
|
+
# end
|
61
|
+
# def first
|
62
|
+
# self.notes.send(:first)
|
63
|
+
# end
|
64
|
+
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module Til
|
2
|
+
class NoteWriter
|
3
|
+
attr_reader :title
|
4
|
+
|
5
|
+
def initialize title
|
6
|
+
@title = title
|
7
|
+
end
|
8
|
+
|
9
|
+
def call(if_modified, if_unmodified)
|
10
|
+
temporary_note = TemporaryNote.new
|
11
|
+
temporary_note.write("# #{title}\n\n")
|
12
|
+
temporary_note.edit(if_modified, if_unmodified)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
class TemporaryNote
|
17
|
+
attr_reader :tempfile
|
18
|
+
|
19
|
+
def initialize(tempfile = Tempfile.new(["new_note_content", ".md"]))
|
20
|
+
@tempfile = tempfile
|
21
|
+
end
|
22
|
+
|
23
|
+
def write(text)
|
24
|
+
File.write(path, text)
|
25
|
+
end
|
26
|
+
|
27
|
+
def text
|
28
|
+
File.read(path)
|
29
|
+
end
|
30
|
+
|
31
|
+
def edit(if_modified, if_unmodified)
|
32
|
+
original_text = text
|
33
|
+
system(ENV["EDITOR"], path)
|
34
|
+
modified_text = text
|
35
|
+
|
36
|
+
if original_text == modified_text
|
37
|
+
if_unmodified.call
|
38
|
+
else
|
39
|
+
if_modified.call(modified_text)
|
40
|
+
end
|
41
|
+
|
42
|
+
finish_editing
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def path
|
48
|
+
tempfile.path
|
49
|
+
end
|
50
|
+
|
51
|
+
def finish_editing
|
52
|
+
tempfile.close
|
53
|
+
tempfile.unlink
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
end
|
data/lib/til/settings.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
|
3
|
+
module Til
|
4
|
+
class Settings
|
5
|
+
attr_reader :settings
|
6
|
+
|
7
|
+
def initialize(config_file)
|
8
|
+
@settings = JSON.parse(File.read(config_file))
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.load
|
12
|
+
self.new(File.expand_path("~/.til/config.json"))
|
13
|
+
end
|
14
|
+
|
15
|
+
def directory
|
16
|
+
File.expand_path(settings["directory"])
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/til/version.rb
ADDED
data/lib/til.rb
ADDED
@@ -0,0 +1,164 @@
|
|
1
|
+
require "til/version"
|
2
|
+
require 'til/cli'
|
3
|
+
require 'til/settings'
|
4
|
+
require 'til/note'
|
5
|
+
require 'til/directory'
|
6
|
+
require 'til/note_writer'
|
7
|
+
require 'til/note_list'
|
8
|
+
require 'til/note_editor'
|
9
|
+
require 'til/note_deleter'
|
10
|
+
|
11
|
+
|
12
|
+
module Til
|
13
|
+
|
14
|
+
DIRECTORY = Settings.load.directory
|
15
|
+
|
16
|
+
HIGHLIGHT_COLORS = {
|
17
|
+
0 => :yellow,
|
18
|
+
1 => :light_blue,
|
19
|
+
2 => :green,
|
20
|
+
3 => :blue,
|
21
|
+
4 => :red,
|
22
|
+
5 => :magenta,
|
23
|
+
6 => :light_magenta,
|
24
|
+
}
|
25
|
+
|
26
|
+
|
27
|
+
def self.print_working_directory
|
28
|
+
puts DIRECTORY
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.open_working_directory
|
32
|
+
system("open", DIRECTORY)
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.new_note(subject, title)
|
36
|
+
if_unmodified = Proc.new do
|
37
|
+
puts "You didn't write anything, so a note wasn't created.".red
|
38
|
+
return
|
39
|
+
end
|
40
|
+
|
41
|
+
if_modified = Proc.new do |note_content|
|
42
|
+
subject_path = DIRECTORY + "/#{subject.downcase}"
|
43
|
+
if !File.directory? subject_path
|
44
|
+
FileUtils.mkdir(subject_path)
|
45
|
+
puts "Created a new directory for #{subject.downcase}"
|
46
|
+
end
|
47
|
+
file_path = subject_path + "/" + title.downcase.gsub(" ", "-") + ".md"
|
48
|
+
|
49
|
+
write_file = File.new(file_path, "w")
|
50
|
+
write_file.write note_content
|
51
|
+
write_file.close
|
52
|
+
puts "You created a new note in ".green + subject.green.bold + ". `til last` to read it, or `til edit --last` to edit it.".green
|
53
|
+
end
|
54
|
+
|
55
|
+
NoteWriter.new(title).call(if_modified, if_unmodified)
|
56
|
+
end
|
57
|
+
|
58
|
+
|
59
|
+
def self.search_results_for(search_terms)
|
60
|
+
matches = NoteList.new
|
61
|
+
Directory.root.notes.each do |note|
|
62
|
+
if note.title.downcase.include?(search_terms.downcase)
|
63
|
+
matches.push note
|
64
|
+
end
|
65
|
+
end
|
66
|
+
matches
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
def self.edit_file(search_term, options)
|
71
|
+
if options[:last]
|
72
|
+
system(ENV["EDITOR"] || "vim", Directory.root.notes.most_recent.path)
|
73
|
+
return
|
74
|
+
end
|
75
|
+
matches = Til.search_results_for(search_term)
|
76
|
+
if matches.length < 1
|
77
|
+
puts "no matches"
|
78
|
+
else
|
79
|
+
system(ENV["EDITOR"] || "vim", matches.filter.path)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def self.remove_file(search_term)
|
84
|
+
matches = Til.search_results_for(search_term)
|
85
|
+
if matches.length < 1
|
86
|
+
puts "no matches"
|
87
|
+
else
|
88
|
+
NoteDeleter.new(matches.filter).delete
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
|
93
|
+
def self.run_git_command(*args)
|
94
|
+
system("git --git-dir=#{DIRECTORY}/.git --work-tree=#{DIRECTORY} #{args.join(" ")}")
|
95
|
+
end
|
96
|
+
|
97
|
+
|
98
|
+
def self.run_grep_command(*args)
|
99
|
+
system("grep -r #{args.join(" ")} #{DIRECTORY}")
|
100
|
+
end
|
101
|
+
|
102
|
+
def self.run_ag_command(*args)
|
103
|
+
system("ag #{args.join(" ")} #{DIRECTORY}")
|
104
|
+
end
|
105
|
+
|
106
|
+
|
107
|
+
def self.print_most_recent_note quantity
|
108
|
+
Directory.root.notes.sort_by_modified_time.take(quantity).each {|note| Til.print note}
|
109
|
+
end
|
110
|
+
|
111
|
+
def self.print_all_notes
|
112
|
+
Directory.root.notes.each {|note| Til.print note}
|
113
|
+
end
|
114
|
+
|
115
|
+
def self.print_all_notes_in(subject)
|
116
|
+
Directory.for(subject).notes.each {|note| Til.print note}
|
117
|
+
end
|
118
|
+
|
119
|
+
def self.list_notes_in(subject)
|
120
|
+
notes = Directory.for(subject).notes
|
121
|
+
if notes.empty?
|
122
|
+
puts "You don't seem to have any notes on that subject!"
|
123
|
+
puts "You DO have notes on the following subjects:"
|
124
|
+
Til.list_subjects :flat
|
125
|
+
else
|
126
|
+
Til.enumerate notes
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
def self.list_subjects(list_style=:bullet_points)
|
131
|
+
subjects = Array.new
|
132
|
+
Dir.glob(DIRECTORY + "/*").each do |dirname|
|
133
|
+
subjects.push dirname.gsub(DIRECTORY + "/", "")
|
134
|
+
end
|
135
|
+
if list_style==:flat
|
136
|
+
puts subjects.join(", ")
|
137
|
+
else
|
138
|
+
subjects.each {|subject| puts "- #{subject}"}
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
def self.list_all_notes
|
143
|
+
notes = Directory.root.notes.sort_by_modified_time
|
144
|
+
puts "Listing all #{notes.length} notes: "
|
145
|
+
Til.enumerate notes
|
146
|
+
end
|
147
|
+
|
148
|
+
def self.print note
|
149
|
+
puts note.subject.underline + ": " + note.title.bold + " (" + note.pretty_printed_mtime + ")"
|
150
|
+
puts note.content
|
151
|
+
end
|
152
|
+
|
153
|
+
def self.enumerate notes
|
154
|
+
subjects_seen = Array.new
|
155
|
+
longest_subject_length = notes.sort_by{|note| note.subject.length}.last.subject.length
|
156
|
+
notes.each do |note|
|
157
|
+
subjects_seen.push(note.subject) if !subjects_seen.include?(note.subject)
|
158
|
+
color_index = subjects_seen.index(note.subject) % HIGHLIGHT_COLORS.length
|
159
|
+
color = HIGHLIGHT_COLORS[color_index]
|
160
|
+
spacing = " " * (longest_subject_length - note.subject.length)
|
161
|
+
puts note.subject.colorize(color) + ": " + spacing + note.title.bold + " (" + note.pretty_printed_mtime + ")"
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
data/til.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'til/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "til_cli"
|
8
|
+
spec.version = Til::VERSION
|
9
|
+
spec.authors = ["Kevin"]
|
10
|
+
spec.email = ["litchfield.kevin+gs@gmail.com"]
|
11
|
+
spec.summary = %q{Generate new notes about stuff you learned}
|
12
|
+
spec.homepage = ""
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
21
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
22
|
+
spec.add_dependency "thor", "~> 0.19.1"
|
23
|
+
spec.add_dependency "colorize", "~> 0.7.5"
|
24
|
+
spec.add_dependency "json", "1.8.1"
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,134 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: til_cli
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kevin
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-03-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: thor
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.19.1
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.19.1
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: colorize
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.7.5
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.7.5
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: json
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 1.8.1
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 1.8.1
|
83
|
+
description:
|
84
|
+
email:
|
85
|
+
- litchfield.kevin+gs@gmail.com
|
86
|
+
executables:
|
87
|
+
- til
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- ".gitignore"
|
92
|
+
- Gemfile
|
93
|
+
- LICENSE.txt
|
94
|
+
- README.md
|
95
|
+
- Rakefile
|
96
|
+
- bin/til
|
97
|
+
- lib/til.rb
|
98
|
+
- lib/til/cli.rb
|
99
|
+
- lib/til/directory.rb
|
100
|
+
- lib/til/note.rb
|
101
|
+
- lib/til/note_deleter.rb
|
102
|
+
- lib/til/note_editor.rb
|
103
|
+
- lib/til/note_finder.rb
|
104
|
+
- lib/til/note_list.rb
|
105
|
+
- lib/til/note_writer.rb
|
106
|
+
- lib/til/settings.rb
|
107
|
+
- lib/til/version.rb
|
108
|
+
- til.gemspec
|
109
|
+
homepage: ''
|
110
|
+
licenses:
|
111
|
+
- MIT
|
112
|
+
metadata: {}
|
113
|
+
post_install_message:
|
114
|
+
rdoc_options: []
|
115
|
+
require_paths:
|
116
|
+
- lib
|
117
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
118
|
+
requirements:
|
119
|
+
- - ">="
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '0'
|
122
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
123
|
+
requirements:
|
124
|
+
- - ">="
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: '0'
|
127
|
+
requirements: []
|
128
|
+
rubyforge_project:
|
129
|
+
rubygems_version: 2.2.2
|
130
|
+
signing_key:
|
131
|
+
specification_version: 4
|
132
|
+
summary: Generate new notes about stuff you learned
|
133
|
+
test_files: []
|
134
|
+
has_rdoc:
|