yac 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.
- data/README.cn +57 -0
- data/README.rdoc +58 -0
- data/bin/yac +4 -0
- data/lib/yac.rb +232 -0
- data/resources/yacrc +46 -0
- data/yac.gemspec +32 -0
- metadata +69 -0
data/README.cn
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
= YAC => Yet Another Cheet (Powered By Ruby)
|
2
|
+
|
3
|
+
== FEATURES:
|
4
|
+
YAC was inspired by 'chit' (http://github.com/robin/chit) by robin and 'cheat' (http://cheat.errtheblog.com/) by Chris Wanstrath
|
5
|
+
what's the different:
|
6
|
+
@@@Colorful and Sexy!@@@
|
7
|
+
|
8
|
+
== How To Use
|
9
|
+
|
10
|
+
=== 初始化一个仓库:
|
11
|
+
$ yac init
|
12
|
+
=== 得到cheat表:
|
13
|
+
$ yac [cheatsheet]
|
14
|
+
=== 修改一个cheat表
|
15
|
+
$ yac edit [cheatsheet]
|
16
|
+
=== 加入一个cheat表
|
17
|
+
$ yac add [cheatsheet]
|
18
|
+
=== 删除一个cheat表
|
19
|
+
$ yac rm [cheatsheet]
|
20
|
+
=== 按照cheat表的文件名搜索
|
21
|
+
$ yac name [keyword]
|
22
|
+
=== 按照cheat表的内容搜索
|
23
|
+
$ yac content [keyword]
|
24
|
+
=== 更新git仓库
|
25
|
+
$ yac update main 更新主仓库
|
26
|
+
$ yac update private 更新个人仓库
|
27
|
+
$ yac update 全部更新
|
28
|
+
=== 帮助
|
29
|
+
$ yac help
|
30
|
+
=== 打开仓库shell => Comming Soon :)
|
31
|
+
$ yac shell main 打开主仓库的shell
|
32
|
+
$ yac shell 打开个人仓库的shell
|
33
|
+
=== 文档格式
|
34
|
+
使用.ch后缀,在行首加一个=为一级标题,加N个=为N级标题,不同级别标题可以加入不同颜色高亮
|
35
|
+
在行首加入#将忽略该行,使用 '\#'可以得到 '#'的效果
|
36
|
+
在某词两端加入三个@,例:@@\@ HI @@\@(去掉两个/)将会高亮 HI
|
37
|
+
=== 设置高亮的颜色
|
38
|
+
默认用主目录下的 .yacrc来设置,详细内容,参见 resources目录 yacrc文件
|
39
|
+
=== 其它
|
40
|
+
在 表名/关键词 前加入@将会只搜索主仓库
|
41
|
+
更多性感使用方法,参见源码 :)
|
42
|
+
|
43
|
+
== REQUIREMENTS:
|
44
|
+
|
45
|
+
* Ruby
|
46
|
+
* rubygems
|
47
|
+
* git
|
48
|
+
|
49
|
+
== LICENSE:
|
50
|
+
|
51
|
+
This software is shared by GPL3 License
|
52
|
+
|
53
|
+
Copyright (c) 2008 Jinzhu Zhang
|
54
|
+
|
55
|
+
== BY: Jinzhu Zhang
|
56
|
+
http://www.zhangjinzhu.com
|
57
|
+
wosmvp (no-spam) gmail (no-spam) com
|
data/README.rdoc
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
= YAC => Yet Another Cheet (Powered By Ruby)
|
2
|
+
|
3
|
+
== FEATURES:
|
4
|
+
YAC was inspired by 'chit' (http://github.com/robin/chit) by robin and 'cheat' (http://cheat.errtheblog.com/) by Chris Wanstrath
|
5
|
+
what's the different:
|
6
|
+
@@@Colorful and Sexy!@@@
|
7
|
+
|
8
|
+
== How To Use
|
9
|
+
|
10
|
+
=== To initialize repositories:
|
11
|
+
$ yac init
|
12
|
+
=== To get a cheat sheet:
|
13
|
+
$ yac [cheatsheet]
|
14
|
+
=== To edit a cheat sheet
|
15
|
+
$ yac edit [cheatsheet]
|
16
|
+
=== To add a cheat sheet
|
17
|
+
$ yac add [cheatsheet]
|
18
|
+
=== To rm a cheat sheet
|
19
|
+
$ yac rm [cheatsheet]
|
20
|
+
=== Search according the sheets name
|
21
|
+
$ yac name [keyword]
|
22
|
+
=== Search according the sheets content
|
23
|
+
$ yac content [keyword]
|
24
|
+
=== Update repositories
|
25
|
+
$ yac update main => Update main repository
|
26
|
+
Update the main stockroom
|
27
|
+
$ yac update private => Update private repository
|
28
|
+
$ yac update => Update All
|
29
|
+
=== Help
|
30
|
+
$ yac help
|
31
|
+
=== Shell => Comming Soon :)
|
32
|
+
$ yac shell main => Open the main repository's shell
|
33
|
+
$ yac shell => Open the private repository's shell
|
34
|
+
=== Documents format
|
35
|
+
Use .ch as the suffix ,At the beginning of the row,plus N = for the N-class title
|
36
|
+
Use '#' at the beginning of a row to comment the line,You can use '\#' to get '#'
|
37
|
+
Use three @ wrap some words to highlight it,for example: @@\@ HI @@\@ (remove the \) will highlight HI
|
38
|
+
=== Set the color of highlight
|
39
|
+
Default use .yacrc under home directory to set,, details, see the example file under the resources directory
|
40
|
+
=== Others
|
41
|
+
Add @ before [cheatsheet]/[keyword] will only search the main depot
|
42
|
+
See also the source code to get more sexy ways
|
43
|
+
|
44
|
+
== REQUIREMENTS:
|
45
|
+
|
46
|
+
* Ruby
|
47
|
+
* rubygems
|
48
|
+
* git
|
49
|
+
|
50
|
+
== LICENSE:
|
51
|
+
|
52
|
+
This software is shared by GPL3 License
|
53
|
+
|
54
|
+
Copyright (c) 2008 Jinzhu Zhang
|
55
|
+
|
56
|
+
== BY: Jinzhu Zhang
|
57
|
+
http://www.zhangjinzhu.com
|
58
|
+
wosmvp (no-spam) gmail (no-spam) com
|
data/bin/yac
ADDED
data/lib/yac.rb
ADDED
@@ -0,0 +1,232 @@
|
|
1
|
+
%w(rubygems git fileutils yaml).each {|f| require f}
|
2
|
+
|
3
|
+
module Yac
|
4
|
+
extend self
|
5
|
+
|
6
|
+
CHITRC = File.join("#{ENV['HOME']}",".chitrc")
|
7
|
+
FileUtils.cp(File.join(File.dirname(__FILE__), "..","resources","yacrc"), CHITRC) unless File.exist?(CHITRC)
|
8
|
+
CONFIG = YAML.load_file(File.join(ENV['HOME'],".yacrc"))
|
9
|
+
CONFIG["root"] ||= File.join(ENV['HOME'],".yac")
|
10
|
+
|
11
|
+
@main_path = File.join(CONFIG["root"],"/main/")
|
12
|
+
@pri_path = File.join(CONFIG["root"],"/private/")
|
13
|
+
@main_git = Git.open(@main_path)
|
14
|
+
@pri_git = Git.open(@pri_path)
|
15
|
+
|
16
|
+
def new(args)
|
17
|
+
@all_result = []
|
18
|
+
help && exit if args.empty?
|
19
|
+
case args.first
|
20
|
+
when "show" then show(args[1,args.size])
|
21
|
+
when "name" then search(args[1,args.size],"name")
|
22
|
+
when "content" then search(args[1,args.size],"content")
|
23
|
+
when "update" then update(args[1,args.size])
|
24
|
+
when "add" then add(args[1,args.size])
|
25
|
+
when "edit" then edit(args[1,args.size])
|
26
|
+
when "help" then help
|
27
|
+
when "shell" then shell(args[1,args.size])
|
28
|
+
when "rm" then rm(args[1,args.size])
|
29
|
+
when "init" then init
|
30
|
+
else show(args)
|
31
|
+
end
|
32
|
+
show_possible_result
|
33
|
+
end
|
34
|
+
|
35
|
+
def show(args)
|
36
|
+
args.each {|x| show_single(x)}
|
37
|
+
end
|
38
|
+
|
39
|
+
def search(args,type = "name")
|
40
|
+
args.each {|x| search_single(x,type)}
|
41
|
+
end
|
42
|
+
|
43
|
+
def update(args)
|
44
|
+
begin
|
45
|
+
if args
|
46
|
+
@main_path.pull if args.to_s =~ /main/
|
47
|
+
@pri_git.pull if args.to_s =~ /pri/
|
48
|
+
else
|
49
|
+
@main_path.pull
|
50
|
+
@pri_git.pull
|
51
|
+
end
|
52
|
+
rescue
|
53
|
+
puts "ERROR: can not update #{args}"
|
54
|
+
puts $!
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def edit(args)
|
59
|
+
args.each {|x| edit_single(x)}
|
60
|
+
end
|
61
|
+
alias add edit
|
62
|
+
|
63
|
+
def rm(args)
|
64
|
+
args.each {|x| rm_single(x)}
|
65
|
+
end
|
66
|
+
|
67
|
+
def help
|
68
|
+
format_file(File.dirname(__FILE__)+"/../README")
|
69
|
+
end
|
70
|
+
|
71
|
+
def shell(args = "pri")
|
72
|
+
puts "Comming Soon :)"
|
73
|
+
#case args.to_s
|
74
|
+
#when /main/
|
75
|
+
# system("cd #{@main_path}")
|
76
|
+
#when /pri/
|
77
|
+
# system("cd #{@pri_path}")
|
78
|
+
#end
|
79
|
+
end
|
80
|
+
|
81
|
+
protected
|
82
|
+
def format_file(file)
|
83
|
+
@level = 0
|
84
|
+
File.new(file).each do |x|
|
85
|
+
format_section(x)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def format_section(section)
|
90
|
+
case section
|
91
|
+
when /^(=+)\s+(.*)/
|
92
|
+
@level = $1.size
|
93
|
+
puts "\033[" + CONFIG["level#{@level}"].to_s + "m" + "\s"*2*(@level-1) + $2 +"\033[0m"
|
94
|
+
when /^(\s*)#/
|
95
|
+
else
|
96
|
+
puts section.sub(/^\#/,"#").sub(/^\s*/, "\s" * @level * 2 ).gsub(/@@@(.*)@@@/,"\033[" + CONFIG["empha"].to_s + "m" + '\1' + "\033[0m")
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
def full_path(args)
|
101
|
+
if args =~ /^@/
|
102
|
+
@file_path = @main_path + args.sub(/^@/,"") + ".ch"
|
103
|
+
@working_git = @main_git
|
104
|
+
else
|
105
|
+
@file_path = @pri_path + args + ".ch"
|
106
|
+
@working_git = @pri_git
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
def rm_single(args)
|
111
|
+
full_path(args)
|
112
|
+
begin
|
113
|
+
@working_git.remove(@file_path)
|
114
|
+
@working_git.commit_all("#{args.sub(/^@/,"")}.ch removed")
|
115
|
+
rescue Git::GitExecuteError
|
116
|
+
FileUtils.rm_rf(@file_path)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
def edit_single(args)
|
121
|
+
full_path(args)
|
122
|
+
system("#{editor} #{@file_path}")
|
123
|
+
begin
|
124
|
+
@working_git.add
|
125
|
+
@working_git.commit_all(" #{args.sub(/^@/,"")}.ch Updated")
|
126
|
+
rescue
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
def editor
|
131
|
+
ENV['VISUAL'] || ENV['EDITOR'] || "vim"
|
132
|
+
end
|
133
|
+
|
134
|
+
def show_single(args)
|
135
|
+
result = search_single(args)
|
136
|
+
if result.size == 1
|
137
|
+
puts "\n\033[#{CONFIG["filename"]}m#{result.first}\033[0m\n"
|
138
|
+
format_file(result.first)
|
139
|
+
else
|
140
|
+
result.map do |x|
|
141
|
+
if x =~ /\/#{args}\.ch/
|
142
|
+
puts "\n\033[#{CONFIG["filename"]}m#{x}\033[0m\n"
|
143
|
+
format_file(x)
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
def search_single(args,type="name")
|
150
|
+
if type =~ /name/
|
151
|
+
search_name(args)
|
152
|
+
else
|
153
|
+
search_content(args)
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
def search_name(args)
|
158
|
+
if args =~ /^@/ && main = args.sub(/^@/,"")
|
159
|
+
@private_result = []
|
160
|
+
@main_result = @main_git.ls_files.keys.grep(/#{main}/)
|
161
|
+
else
|
162
|
+
@private_result = @pri_git.ls_files.keys.grep(/#{args}/)
|
163
|
+
@main_result = @main_git.ls_files.keys.grep(/#{args}/)
|
164
|
+
end
|
165
|
+
#ADD to all possible result
|
166
|
+
@all_result << @main_result.collect {|x| "@" + x}
|
167
|
+
@all_result << @private_result
|
168
|
+
|
169
|
+
#Remove duplicate files
|
170
|
+
@private_result.map do |x|
|
171
|
+
@main_result.delete(x)
|
172
|
+
end
|
173
|
+
#Return full path
|
174
|
+
return (@main_result.collect {|x| @main_path +x}).concat(@private_result.collect {|x| @pri_path +x})
|
175
|
+
end
|
176
|
+
|
177
|
+
def search_content(args)
|
178
|
+
@main_git.grep(args).each do |file, lines|
|
179
|
+
title = title_of_file(file.split(':')[1])
|
180
|
+
lines.each do |l|
|
181
|
+
puts "@#{title}:#{l[0]}: #{l[1]}"
|
182
|
+
end
|
183
|
+
end
|
184
|
+
@pri_git.grep(args).each do |file, lines|
|
185
|
+
title = title_of_file(file.split(':')[1])
|
186
|
+
lines.each do |l|
|
187
|
+
puts "#{title}:#{l[0]}: #{l[1]}"
|
188
|
+
end
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
def title_of_file(f)
|
193
|
+
f[0..((f.rindex('.')||0) - 1)]
|
194
|
+
end
|
195
|
+
|
196
|
+
def show_possible_result
|
197
|
+
puts "\n\033[" + CONFIG["possible_result_title"].to_s + "mALL POSSIBLE RESULT:\n\033[0m\033[" +CONFIG["possible_result_content"].to_s + "m" + @all_result.join("\s"*2) + "\033[0m" unless @all_result.to_s.empty?
|
198
|
+
end
|
199
|
+
|
200
|
+
def init
|
201
|
+
FileUtils.mkdir_p(CONFIG['root'])
|
202
|
+
if CONFIG['main']['clone-from']
|
203
|
+
if File.exist?(@main_path)
|
204
|
+
puts "Main repository has already been initialized."
|
205
|
+
else
|
206
|
+
puts "Initialize main repository from #{CONFIG['main']['clone-from']} to #{CONFIG['root']}/main"
|
207
|
+
Git.clone(CONFIG['main']['clone-from'], 'main', :path => CONFIG['root'])
|
208
|
+
puts "Main repository initialized."
|
209
|
+
end
|
210
|
+
else
|
211
|
+
puts "ERROR: configuration for main repository repository is missing!"
|
212
|
+
return
|
213
|
+
end
|
214
|
+
|
215
|
+
unless File.exist?(@pri_path)
|
216
|
+
if CONFIG['private'] && CONFIG['private']['clone-from']
|
217
|
+
puts "Initialize private repository from #{CONFIG['private']['clone-from']} to #{CONFIG['root']}/private"
|
218
|
+
Git.clone(CONFIG['private']['clone-from'], 'private', :path => CONFIG['root'])
|
219
|
+
puts "Private repository initialized."
|
220
|
+
else
|
221
|
+
puts "Initialize private repository from scratch to #{CONFIG['root']}/private"
|
222
|
+
git = Git.init(@pri_path)
|
223
|
+
git.add
|
224
|
+
git.commit_all("init private repository")
|
225
|
+
puts "Private repository initialized."
|
226
|
+
end
|
227
|
+
else
|
228
|
+
puts "Private repository has already been initialized."
|
229
|
+
end
|
230
|
+
puts "Repository init done."
|
231
|
+
end
|
232
|
+
end
|
data/resources/yacrc
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
#root:
|
2
|
+
# add_if_not_exist: true
|
3
|
+
main:
|
4
|
+
clone-from: git://github.com/wosmvp/cheat.git
|
5
|
+
# push-to:
|
6
|
+
private:
|
7
|
+
# clone-from:
|
8
|
+
# push-to:
|
9
|
+
|
10
|
+
|
11
|
+
#Set Color
|
12
|
+
#1 - Change text to hicolor (bold) mode
|
13
|
+
#4 - " " " Underline
|
14
|
+
#5 - " " " Blink
|
15
|
+
#8 - " " " Hidden (same color as bg)
|
16
|
+
#30 - " " " Black
|
17
|
+
#31 - " " " Red
|
18
|
+
#32 - " " " Green
|
19
|
+
#33 - " " " Yellow
|
20
|
+
#34 - " " " Blue
|
21
|
+
#35 - " " " Magenta
|
22
|
+
#36 - " " " Cyan
|
23
|
+
#37 - " " " White
|
24
|
+
#40 - Change background to Black
|
25
|
+
#41 - " " " Red
|
26
|
+
#42 - " " " Green
|
27
|
+
#43 - " " " Yellow
|
28
|
+
#44 - " " " Blue
|
29
|
+
#45 - " " " Magenta
|
30
|
+
#46 - " " " Cyan
|
31
|
+
#47 - " " " White
|
32
|
+
#0 - Turn off all attributes.
|
33
|
+
#7 - Change to Black text on a White background
|
34
|
+
|
35
|
+
level1: 31
|
36
|
+
level2: 32
|
37
|
+
level3: 33
|
38
|
+
level4: 34
|
39
|
+
level5: 0;31;40
|
40
|
+
level6: 0;31;40
|
41
|
+
level7: 0;31;40
|
42
|
+
|
43
|
+
empha: 32;40
|
44
|
+
possible_result_title: 33;41
|
45
|
+
possible_result_content: 31
|
46
|
+
filename: 31
|
data/yac.gemspec
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = %q{yac}
|
7
|
+
s.version = "0.0.1"
|
8
|
+
|
9
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
10
|
+
s.authors = ["Jinzhu Zhang"]
|
11
|
+
s.date = %q{2008-10-10}
|
12
|
+
s.homepage = %q{http://www.zhangjinzhu.com}
|
13
|
+
s.default_executable = %q{yac}
|
14
|
+
s.summary = %q{Yet Another Cheat}
|
15
|
+
s.email = ["wosmvp@gmail.com"]
|
16
|
+
s.executables = ["yac"]
|
17
|
+
|
18
|
+
files = []
|
19
|
+
files += Dir.glob('lib/*')
|
20
|
+
files += Dir.glob('bin/*')
|
21
|
+
files += Dir.glob('resources/*')
|
22
|
+
files += %w[README.rdoc README.cn yac.gemspec]
|
23
|
+
s.files = files
|
24
|
+
|
25
|
+
s.has_rdoc = true
|
26
|
+
|
27
|
+
s.require_paths = ["lib"]
|
28
|
+
s.extra_rdoc_files = "README.rdoc"
|
29
|
+
s.rdoc_options = ["--main", "README.rdoc"]
|
30
|
+
s.rubyforge_project = %q{yac}
|
31
|
+
s.add_dependency("schacon-git", ">1.0.0")
|
32
|
+
end
|
metadata
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: yac
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jinzhu Zhang
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-10-10 00:00:00 +08:00
|
13
|
+
default_executable: yac
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: schacon-git
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 1.0.0
|
24
|
+
version:
|
25
|
+
description:
|
26
|
+
email:
|
27
|
+
- wosmvp@gmail.com
|
28
|
+
executables:
|
29
|
+
- yac
|
30
|
+
extensions: []
|
31
|
+
|
32
|
+
extra_rdoc_files:
|
33
|
+
- README.rdoc
|
34
|
+
files:
|
35
|
+
- lib/yac.rb
|
36
|
+
- bin/yac
|
37
|
+
- resources/yacrc
|
38
|
+
- README.rdoc
|
39
|
+
- README.cn
|
40
|
+
- yac.gemspec
|
41
|
+
has_rdoc: true
|
42
|
+
homepage: http://www.zhangjinzhu.com
|
43
|
+
post_install_message:
|
44
|
+
rdoc_options:
|
45
|
+
- --main
|
46
|
+
- README.rdoc
|
47
|
+
require_paths:
|
48
|
+
- lib
|
49
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: "0"
|
54
|
+
version:
|
55
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: "0"
|
60
|
+
version:
|
61
|
+
requirements: []
|
62
|
+
|
63
|
+
rubyforge_project: yac
|
64
|
+
rubygems_version: 1.2.0
|
65
|
+
signing_key:
|
66
|
+
specification_version: 2
|
67
|
+
summary: Yet Another Cheat
|
68
|
+
test_files: []
|
69
|
+
|