til_cli 0.0.2 → 0.0.3
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/LICENSE.txt +1 -1
- data/README.md +9 -24
- data/lib/til.rb +22 -10
- data/lib/til/cli.rb +21 -21
- data/lib/til/initializer.rb +24 -0
- data/lib/til/note_editor.rb +1 -8
- data/lib/til/settings.rb +16 -2
- data/lib/til/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d407f12beba107ba569ca26aa41c4dbe553e873e
|
4
|
+
data.tar.gz: 9869122a9a035906d72ebbd57d36d66354fad19e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 90e17b8c04f47edbd94523d29f67aadd4d025fbed09c234fd67685f85d765aa0eebb0b35291fb2d6fcceb11bf464ef139de5b8c232ab5b46c14694a7f4de396a
|
7
|
+
data.tar.gz: 2ead72d1c5d2429f7386aa759857f15ac9201b79b99f5be5c1e6d3f1d614b7aa6be48e3e46014169e22d90b41b1e49f44971fadf2048ac99f65d191d4372f3cb
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -1,31 +1,16 @@
|
|
1
|
-
#
|
1
|
+
# `til_cli`
|
2
2
|
|
3
|
-
|
3
|
+
Command-line notetaking application: a CRUD interface to a repo of "Today I Learned" notes. Inspired by the format of https://github.com/thoughtbot/til. Uses `$EDITOR` to create and edit notes, wraps Git for convenience, more features to come.
|
4
4
|
|
5
5
|
## Installation
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
```ruby
|
10
|
-
gem 'til'
|
6
|
+
```
|
7
|
+
gem install til_cli
|
11
8
|
```
|
12
9
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
Or install it yourself as:
|
18
|
-
|
19
|
-
$ gem install til
|
10
|
+
## Setup
|
11
|
+
```
|
12
|
+
til init
|
13
|
+
```
|
20
14
|
|
21
15
|
## 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
|
16
|
+
Run `til help` for usage information.
|
data/lib/til.rb
CHANGED
@@ -7,12 +7,12 @@ require 'til/note_writer'
|
|
7
7
|
require 'til/note_list'
|
8
8
|
require 'til/note_editor'
|
9
9
|
require 'til/note_deleter'
|
10
|
-
|
10
|
+
require 'til/initializer'
|
11
11
|
|
12
12
|
module Til
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
DIRECTORY = -> () { Settings.load.directory }
|
14
|
+
GITHUB_REPO = -> () { Settings.load.github_repo }
|
15
|
+
EDITOR = ENV["VISUAL"] || ENV["EDITOR"] || "vim"
|
16
16
|
HIGHLIGHT_COLORS = {
|
17
17
|
0 => :yellow,
|
18
18
|
1 => :light_blue,
|
@@ -23,15 +23,16 @@ module Til
|
|
23
23
|
6 => :light_magenta,
|
24
24
|
}
|
25
25
|
|
26
|
+
def self.init_settings_file_and_notes_repo
|
27
|
+
Initializer.new.create_settings_file unless Settings.settings_file_configured?
|
28
|
+
Initializer.new.create_notes_directory
|
29
|
+
puts "Your settings file is at `#{Settings.settings_file_path}`. Your notes are at `#{DIRECTORY}`."
|
30
|
+
end
|
26
31
|
|
27
32
|
def self.print_working_directory
|
28
33
|
puts DIRECTORY
|
29
34
|
end
|
30
35
|
|
31
|
-
def self.open_working_directory
|
32
|
-
system("open", DIRECTORY)
|
33
|
-
end
|
34
|
-
|
35
36
|
def self.new_note(subject, title)
|
36
37
|
if_unmodified = Proc.new do
|
37
38
|
puts "You didn't write anything, so a note wasn't created.".red
|
@@ -69,14 +70,14 @@ module Til
|
|
69
70
|
|
70
71
|
def self.edit_file(search_term, options)
|
71
72
|
if options[:last]
|
72
|
-
system(
|
73
|
+
system(EDITOR, Directory.root.notes.most_recent.path)
|
73
74
|
return
|
74
75
|
end
|
75
76
|
matches = Til.search_results_for(search_term)
|
76
77
|
if matches.length < 1
|
77
78
|
puts "no matches"
|
78
79
|
else
|
79
|
-
system(
|
80
|
+
system(EDITOR, matches.filter.path)
|
80
81
|
end
|
81
82
|
end
|
82
83
|
|
@@ -89,6 +90,17 @@ module Til
|
|
89
90
|
end
|
90
91
|
end
|
91
92
|
|
93
|
+
def self.open_github_page_for_repo
|
94
|
+
if GITHUB_REPO
|
95
|
+
else
|
96
|
+
begin
|
97
|
+
repo = %x|git --git-dir=#{DIRECTORY}/.git --work-tree=#{DIRECTORY} remote -v|.scan(/:(.*).git/).flatten.first
|
98
|
+
system("open https://www.github.com/#{repo}")
|
99
|
+
rescue
|
100
|
+
puts "You don't appear to have a GitHub remote repository for your notes."
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
92
104
|
|
93
105
|
def self.run_git_command(*args)
|
94
106
|
system("git --git-dir=#{DIRECTORY}/.git --work-tree=#{DIRECTORY} #{args.join(" ")}")
|
data/lib/til/cli.rb
CHANGED
@@ -5,28 +5,42 @@ require 'date'
|
|
5
5
|
require 'json'
|
6
6
|
|
7
7
|
module Til
|
8
|
+
class Cli < Thor
|
9
|
+
|
10
|
+
desc "init", "Generate a settings file if one doesn't already exist."
|
11
|
+
def init
|
12
|
+
Til.init_settings_file_and_notes_repo
|
13
|
+
end
|
8
14
|
|
15
|
+
desc "github", "If your notes have a remote repository on Github, open it."
|
16
|
+
def github
|
17
|
+
Til.open_github_page_for_repo
|
18
|
+
end
|
19
|
+
|
20
|
+
desc "edit [SEARCH TERM]", "Edit file that matches search for [SEARCH TERM]."
|
21
|
+
long_desc "`--last` flag"
|
22
|
+
option :last, type: :boolean
|
23
|
+
def edit(keyword="")
|
24
|
+
Til.edit_file(keyword, options)
|
25
|
+
end
|
9
26
|
|
10
|
-
class Cli < Thor
|
11
27
|
desc "new SUBJECT \"TITLE\"", "Generate a new note with TITLE about SUBJECT. TITLE should be quoted and shell metacharacters escaped."
|
12
28
|
def new(subject, title)
|
13
29
|
Til.new_note(subject, title)
|
14
30
|
end
|
15
31
|
|
16
32
|
desc "ls [SUBJECT]", "List all notes [on SUBJECT]"
|
33
|
+
option :subjects, type: :boolean
|
17
34
|
def ls(subject = nil)
|
18
|
-
if
|
35
|
+
if options[:subjects]
|
36
|
+
Til.list_subjects
|
37
|
+
elsif subject
|
19
38
|
Til.list_notes_in(subject)
|
20
39
|
else
|
21
40
|
Til.list_all_notes
|
22
41
|
end
|
23
42
|
end
|
24
43
|
|
25
|
-
desc "subjects", "List all subjects"
|
26
|
-
def subjects
|
27
|
-
Til.list_subjects :bullet_points
|
28
|
-
end
|
29
|
-
|
30
44
|
desc "pwd", "Print the path of your TIL working directory"
|
31
45
|
def pwd
|
32
46
|
Til.print_working_directory
|
@@ -37,11 +51,6 @@ module Til
|
|
37
51
|
Til.print_most_recent_note quantity.to_i
|
38
52
|
end
|
39
53
|
|
40
|
-
desc "open", "Open TIL working directory"
|
41
|
-
def open
|
42
|
-
Til.open_working_directory
|
43
|
-
end
|
44
|
-
|
45
54
|
desc "cat [SUBJECT]", "Print all notes [on SUBJECT]"
|
46
55
|
def cat(subject=nil)
|
47
56
|
if subject
|
@@ -51,25 +60,16 @@ module Til
|
|
51
60
|
end
|
52
61
|
end
|
53
62
|
|
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
63
|
desc "git COMMAND", "Run Git COMMAND in TIL directory"
|
62
64
|
def git(*args)
|
63
65
|
Til.run_git_command(*args)
|
64
66
|
end
|
65
67
|
|
66
|
-
|
67
68
|
desc "grep COMMAND", "Run grep COMMAND in TIL directory"
|
68
69
|
def grep(*args)
|
69
70
|
Til.run_grep_command(*args)
|
70
71
|
end
|
71
72
|
|
72
|
-
|
73
73
|
desc "ag COMMAND", "Run Silver Searcher COMMAND in TIL directory"
|
74
74
|
def ag(*args)
|
75
75
|
Til.run_ag_command(*args)
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
|
3
|
+
module Til
|
4
|
+
class Initializer
|
5
|
+
include Thor::Base
|
6
|
+
include Thor::Actions
|
7
|
+
|
8
|
+
def create_settings_file
|
9
|
+
notes_directory = ask("What directory do you want your notes to live in? (If you have no preference, `~/til` is a good option.)\n>")
|
10
|
+
settings_hash = {
|
11
|
+
"directory" => notes_directory
|
12
|
+
}
|
13
|
+
puts "Creating a settings file at `#{Settings.settings_file_path}`."
|
14
|
+
File.open(Settings.settings_file_path, "w") do |f|
|
15
|
+
f.write(settings_hash.to_json)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def create_notes_directory
|
20
|
+
d = Settings.load.notes_directory
|
21
|
+
FileUtils.mkdir_p(File.expand_path(d))
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/til/note_editor.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
# require 'github-markdown-preview' #!! seems to be slowing things down a lot if placed in til.rb
|
2
|
-
|
3
1
|
module Til
|
4
2
|
class NoteEditor
|
5
3
|
attr_reader :path
|
@@ -13,12 +11,7 @@ module Til
|
|
13
11
|
end
|
14
12
|
|
15
13
|
def edit
|
16
|
-
|
17
|
-
# preview.watch
|
18
|
-
# system("open", preview.preview_file)
|
19
|
-
system(ENV["EDITOR"] || "vim", path)
|
20
|
-
# preview.end_watch
|
21
|
-
# preview.delete
|
14
|
+
system(EDITOR, path)
|
22
15
|
end
|
23
16
|
end
|
24
17
|
end
|
data/lib/til/settings.rb
CHANGED
@@ -4,16 +4,30 @@ module Til
|
|
4
4
|
class Settings
|
5
5
|
attr_reader :settings
|
6
6
|
|
7
|
+
SETTINGS_FILE_PATH = File.expand_path("~/.til/config.json")
|
8
|
+
|
7
9
|
def initialize(config_file)
|
8
10
|
@settings = JSON.parse(File.read(config_file))
|
9
11
|
end
|
10
12
|
|
13
|
+
def self.settings_file_path
|
14
|
+
SETTINGS_FILE_PATH
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.settings_file_configured?
|
18
|
+
File.exist?(SETTINGS_FILE_PATH)
|
19
|
+
end
|
20
|
+
|
11
21
|
def self.load
|
12
|
-
self.new(
|
22
|
+
self.new(SETTINGS_FILE_PATH)
|
13
23
|
end
|
14
24
|
|
15
|
-
def
|
25
|
+
def notes_directory
|
16
26
|
File.expand_path(settings["directory"])
|
17
27
|
end
|
28
|
+
|
29
|
+
def github_repo
|
30
|
+
settings["github_repo"]
|
31
|
+
end
|
18
32
|
end
|
19
33
|
end
|
data/lib/til/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: til_cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kevin Litchfield
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-04-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -97,6 +97,7 @@ files:
|
|
97
97
|
- lib/til.rb
|
98
98
|
- lib/til/cli.rb
|
99
99
|
- lib/til/directory.rb
|
100
|
+
- lib/til/initializer.rb
|
100
101
|
- lib/til/note.rb
|
101
102
|
- lib/til/note_deleter.rb
|
102
103
|
- lib/til/note_editor.rb
|