robin-chit 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.txt +15 -7
- data/lib/chit.rb +45 -11
- data/resources/chitrc +1 -0
- metadata +1 -1
data/README.txt
CHANGED
@@ -29,13 +29,11 @@ To get a cheat sheet:
|
|
29
29
|
|
30
30
|
$ chit [cheatsheet]
|
31
31
|
|
32
|
-
|
33
|
-
|
34
|
-
To edit a cheat sheet, use the --edit switch.
|
32
|
+
To edit a cheat sheet, use the --edit/-e switch.
|
35
33
|
|
36
34
|
$ cheat [cheatsheet] --edit
|
37
35
|
|
38
|
-
To add a cheat sheet, use the --add switch.
|
36
|
+
To add a cheat sheet, use the --add/-a switch.
|
39
37
|
|
40
38
|
$ cheat [cheatsheet] --add
|
41
39
|
|
@@ -47,7 +45,7 @@ To get your private cheat sheet:
|
|
47
45
|
|
48
46
|
$ chit @[cheatsheet]
|
49
47
|
|
50
|
-
The prefix '@' works the same for both --edit and --add.
|
48
|
+
The prefix '@' works the same for both --edit/-e and --add/-a.
|
51
49
|
|
52
50
|
The cheat sheet can be in a path. For example:
|
53
51
|
|
@@ -57,11 +55,19 @@ will get the cheat sheet 'select' under mysql.
|
|
57
55
|
|
58
56
|
To show all the cheat sheets:
|
59
57
|
|
60
|
-
$ chit [all|
|
58
|
+
$ chit [all|sheets]
|
61
59
|
|
62
60
|
To show all the private cheat sheets:
|
63
61
|
|
64
|
-
$ chit @[all|
|
62
|
+
$ chit @[all|sheets]
|
63
|
+
|
64
|
+
To find cheat sheets begin with 'name', use the --find/-f switch
|
65
|
+
|
66
|
+
$ chit name --find
|
67
|
+
|
68
|
+
To search cheat sheets content with 'text', use the --search/-s switch
|
69
|
+
|
70
|
+
$ chit text --search
|
65
71
|
|
66
72
|
== INSTALL:
|
67
73
|
|
@@ -74,6 +80,8 @@ chit --init
|
|
74
80
|
Before run 'chit', you may want to config ~/.chitrc which is a YAML file.
|
75
81
|
|
76
82
|
* root: local path to store the cheat sheet. By default, it is ~/.chit
|
83
|
+
* add_if_not_exist: when set as 'true', if no sheets found, a new one will be created and waiting for editing. Leave it blank and quit the editor if you don't
|
84
|
+
want to add a new one.
|
77
85
|
* main:
|
78
86
|
* clone-from: where to get the public cheat sheets. You can use git://github.com/robin/chitsheet.git, which is a snap shoot of http://cheat.errtheblog.com/.
|
79
87
|
* private:
|
data/lib/chit.rb
CHANGED
@@ -3,15 +3,15 @@ $:.unshift File.dirname(__FILE__)
|
|
3
3
|
|
4
4
|
module Chit
|
5
5
|
extend self
|
6
|
-
VERSION = '0.0.
|
6
|
+
VERSION = '0.0.4'
|
7
7
|
|
8
8
|
defaults = {
|
9
|
-
'root' => "#{ENV['HOME']}
|
9
|
+
'root' => File.join("#{ENV['HOME']}",".chit")
|
10
10
|
}
|
11
11
|
|
12
|
-
CHITRC = "#{ENV['HOME']}
|
12
|
+
CHITRC = File.join("#{ENV['HOME']}",".chitrc")
|
13
13
|
|
14
|
-
FileUtils.cp(File.join(File.dirname(__FILE__), "
|
14
|
+
FileUtils.cp(File.join(File.dirname(__FILE__), "..","resources","chitrc"), CHITRC) unless File.exist?(CHITRC)
|
15
15
|
|
16
16
|
CONFIG = defaults.merge(YAML.load_file(CHITRC))
|
17
17
|
|
@@ -32,7 +32,13 @@ module Chit
|
|
32
32
|
end
|
33
33
|
|
34
34
|
unless File.exist?(sheet_file)
|
35
|
-
add
|
35
|
+
if args.delete('--no-add').nil? && CONFIG['add_if_not_exist']
|
36
|
+
add(sheet_file)
|
37
|
+
else
|
38
|
+
puts "Error!:\n #{@sheet} not found"
|
39
|
+
puts "Possible sheets:"
|
40
|
+
search_title
|
41
|
+
end
|
36
42
|
else
|
37
43
|
show(sheet_file)
|
38
44
|
end
|
@@ -51,15 +57,31 @@ module Chit
|
|
51
57
|
|
52
58
|
@fullpath = File.join(working_dir, "#{@sheet}.yml")
|
53
59
|
|
54
|
-
add(sheet_file) and return if args.delete('--add')
|
55
|
-
edit(sheet_file) and return if args.delete('--edit')
|
60
|
+
add(sheet_file) and return if (args.delete('--add')||args.delete('-a'))
|
61
|
+
edit(sheet_file) and return if (args.delete('--edit')||args.delete('-e'))
|
62
|
+
search_title and return if (args.delete('--find')||args.delete('-f'))
|
63
|
+
search_content and return if (args.delete('--search')||args.delete('-s'))
|
56
64
|
true
|
57
65
|
end
|
58
66
|
|
59
67
|
def list_all
|
60
|
-
|
61
|
-
|
68
|
+
puts all_sheets.sort.join("\n")
|
69
|
+
end
|
70
|
+
|
71
|
+
def search_content
|
72
|
+
@git.grep(@sheet).each {|file, lines|
|
73
|
+
title = title_of_file(file.split(':')[1])
|
74
|
+
lines.each {|l|
|
75
|
+
puts "#{title}:#{l[0]}: #{l[1]}"
|
76
|
+
}
|
77
|
+
}
|
78
|
+
end
|
79
|
+
|
80
|
+
def search_title
|
81
|
+
reg = Regexp.compile("^#{@sheet}")
|
82
|
+
files = all_sheets.select {|sheet| sheet =~ reg }
|
62
83
|
puts files.sort.join("\n")
|
84
|
+
true
|
63
85
|
end
|
64
86
|
|
65
87
|
def sheet_file
|
@@ -132,9 +154,9 @@ module Chit
|
|
132
154
|
|
133
155
|
def add(sheet_file)
|
134
156
|
unless File.exist?(sheet_file)
|
135
|
-
breaker = sheet_file.rindex(
|
157
|
+
breaker = sheet_file.rindex(File::Separator)+1
|
136
158
|
path = sheet_file[0,breaker]
|
137
|
-
title = @sheet.
|
159
|
+
title = @sheet.split(File::Separator).join('::')
|
138
160
|
FileUtils.mkdir_p(path)
|
139
161
|
yml = {"#{title}" => ''}.to_yaml
|
140
162
|
open(sheet_file, 'w') {|f| f << yml}
|
@@ -153,8 +175,10 @@ module Chit
|
|
153
175
|
@git.add
|
154
176
|
@git.commit_all("-")
|
155
177
|
end
|
178
|
+
true
|
156
179
|
end
|
157
180
|
|
181
|
+
private
|
158
182
|
def editor
|
159
183
|
ENV['VISUAL'] || ENV['EDITOR'] || "vim"
|
160
184
|
end
|
@@ -172,4 +196,14 @@ module Chit
|
|
172
196
|
tempfile.close
|
173
197
|
body
|
174
198
|
end
|
199
|
+
|
200
|
+
def all_sheets
|
201
|
+
@git.ls_files.to_a.map {|f|
|
202
|
+
title_of_file(f[0])}
|
203
|
+
end
|
204
|
+
|
205
|
+
def title_of_file(f)
|
206
|
+
f[0..((f.rindex('.')||0) - 1)]
|
207
|
+
end
|
208
|
+
|
175
209
|
end
|
data/resources/chitrc
CHANGED