wosmvp-yac 0.1.6 → 1.0.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.
- data/README.rdoc +67 -28
- data/lib/format.rb +31 -17
- data/lib/yac.rb +148 -83
- data/resources/yacrc +17 -15
- data/yac.gemspec +4 -4
- metadata +4 -5
- data/README.cn +0 -57
data/README.rdoc
CHANGED
@@ -1,47 +1,86 @@
|
|
1
1
|
= YAC => Yet Another Cheet (Powered By Ruby)
|
2
|
+
YAC was inspired by 'chit' (http://github.com/robin/chit) by robin and 'cheat' (http://cheat.errtheblog.com/) by Chris Wanstrath,But @@@Colorful and Sexy!!!@@@
|
2
3
|
|
3
|
-
==
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
== What?
|
5
|
+
Cheat sheet is a concise set of notes used for quick reference.
|
6
|
+
YAC is a simple sexy command line tool for easy control cheatsheet.(Images can be found here: http://picasaweb.google.com/wosmvp/YacYetAnotherCheat)
|
7
|
+
Yes,It's support Image,PDF,Text, and can be easily enhance :)
|
8
|
+
Install, Use, Enjoy :)
|
9
|
+
|
10
|
+
== Install
|
11
|
+
Make sure you have ruby,git in your system . then:
|
12
|
+
$ (sudo) gem install yac -s http://gems.github.com
|
7
13
|
|
8
14
|
== How To Use
|
9
15
|
|
10
16
|
=== To initialize repositories:
|
11
|
-
|
12
|
-
|
13
|
-
|
17
|
+
When you run any command,The repositories will be initialize automatically.
|
18
|
+
|
19
|
+
=== To show a cheat sheet:
|
20
|
+
$ yac (show) [cheatsheet] ( you can use * for any chars)
|
21
|
+
Eg:
|
22
|
+
$ yac show lin*x
|
23
|
+
|
14
24
|
=== To edit a cheat sheet
|
15
|
-
$ yac edit [cheatsheet]
|
25
|
+
$ yac edit [cheatsheet] (Yes,you can use * for any chars also,then choose one to edit)
|
26
|
+
|
16
27
|
=== To add a cheat sheet
|
17
|
-
$ yac add [cheatsheet]
|
28
|
+
$ yac add [cheatsheet] (OMG,you can also use *)
|
29
|
+
Eg:
|
30
|
+
$ yac li*x/install
|
31
|
+
Then will display all directories match /li*x/,feel freely to choose one of them,
|
32
|
+
A new file named install.ch will be added to the directory!
|
33
|
+
|
18
34
|
=== To rm a cheat sheet
|
19
|
-
$ yac rm [cheatsheet]
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
35
|
+
$ yac rm [cheatsheet] (Sure,you can use *)
|
36
|
+
|
37
|
+
=== Search all sheets
|
38
|
+
$ yac search [keyword] (@@@Take Attention:@@@ You are allowed to use perl-like Regex)
|
39
|
+
Eg:
|
40
|
+
$ yac search lin.*x
|
41
|
+
And Even:
|
42
|
+
$ yac search "r(uby|ails)"
|
43
|
+
|
24
44
|
=== Update repositories
|
25
45
|
$ yac update main => Update main repository
|
26
|
-
$ yac update
|
27
|
-
$ yac update => Update
|
28
|
-
|
29
|
-
$ yac help / yac / -h / --help
|
46
|
+
$ yac update all => Update all repositories
|
47
|
+
$ yac update => Update private repository
|
48
|
+
|
30
49
|
=== Shell
|
31
|
-
$ yac
|
32
|
-
$ yac
|
50
|
+
$ yac sh main => Open the main repository's shell
|
51
|
+
$ yac sh => Open the private repository's shell
|
52
|
+
|
53
|
+
== Repository Push
|
54
|
+
$ yac push main => Push the main repository
|
55
|
+
$ yac push all => Push all repositories
|
56
|
+
$ yac push => Push the private repository
|
57
|
+
|
58
|
+
== Rename a cheatsheet:
|
59
|
+
$ yac mv [orign_name] [new_name]
|
60
|
+
|
61
|
+
=== Help (display this file)
|
62
|
+
$ yac help
|
63
|
+
|
64
|
+
=== Version
|
65
|
+
$ yac -v | version
|
66
|
+
|
33
67
|
=== Documents format
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
68
|
+
All text file add ".ch" as suffix for butter editor highlight
|
69
|
+
(A very very simple vim script can be found here : http://www.vim.org/scripts/script.php?script_id=2399)
|
70
|
+
|
71
|
+
At the beginning of the row,plus N = for the N-class title
|
72
|
+
|
73
|
+
Use '#' at the beginning of a row to comment the line,You can use '\#' for '#'
|
74
|
+
|
75
|
+
Words wrapped by three @ for highlight
|
76
|
+
|
77
|
+
=== The configure file
|
78
|
+
Default use $HOME/.yacrc , See the example file under resources directory
|
79
|
+
|
39
80
|
=== Others
|
40
|
-
Add @ before [
|
41
|
-
See also the source code to get more sexy ways
|
81
|
+
Add @ before [keyword] will only affect the main repository
|
42
82
|
|
43
83
|
== REQUIREMENTS:
|
44
|
-
|
45
84
|
* Ruby
|
46
85
|
* rubygems
|
47
86
|
* git
|
data/lib/format.rb
CHANGED
@@ -1,19 +1,22 @@
|
|
1
1
|
module Format
|
2
|
-
Pdf_Error = "Please Modify ~/.yacrc To Provide A Valid Command To
|
3
|
-
Image_Error = "Please Modify ~/.yacrc To Provide A Valid Command To
|
2
|
+
Pdf_Error = "Please Modify ~/.yacrc To Provide A Valid Command To Operate PDF Document"
|
3
|
+
Image_Error = "Please Modify ~/.yacrc To Provide A Valid Command To Operate Image Document"
|
4
|
+
Doc_Error = "Please Modify ~/.yacrc To Provide A Valid Command To Operate Text Document"
|
4
5
|
|
5
6
|
def format_file(file)
|
6
7
|
@level = 0
|
7
|
-
|
8
|
-
|
9
|
-
|
8
|
+
colorful(file,"filename") if file
|
9
|
+
case `file "#{file}" 2>/dev/null`
|
10
|
+
when / PDF document/
|
11
|
+
puts Pdf_Error unless system("#{Yac::CONFIG["pdf_command"]||'evince'} \"#{file}\" 2>/dev/null")
|
10
12
|
when /( image )|(\.svg)/
|
11
|
-
puts Image_Error unless system("#{Yac::CONFIG["
|
13
|
+
puts Image_Error unless system("#{Yac::CONFIG["image_command"]||'eog'} \"#{file}\" 2>/dev/null")
|
12
14
|
else
|
13
15
|
File.new(file).each do |x|
|
14
16
|
format_section(x)
|
15
17
|
end
|
16
18
|
end
|
19
|
+
rescue
|
17
20
|
end
|
18
21
|
|
19
22
|
def format_section(section,search = false)
|
@@ -22,17 +25,30 @@ module Format
|
|
22
25
|
@level = search ? 1 : $1.size
|
23
26
|
colorful("\s"*2*(@level-1) + $2,"head#{@level}")
|
24
27
|
when /^(\s*)#/
|
28
|
+
colorful(section.sub(/^\s*/,'')) if search
|
29
|
+
else
|
30
|
+
colorful(section.sub(/^\#/,"#").sub(/^\s*/, "\s" * ( @level||0 ) * 2 ))
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def edit_file(file)
|
35
|
+
case `file "#{file}" 2>/dev/null`
|
36
|
+
when / PDF /
|
37
|
+
puts Pdf_Error unless system("#{Yac::CONFIG["pdf_edit_command"]||'ooffice'} \"#{file}\" 2>/dev/null")
|
38
|
+
when /( image )|(\.svg)/
|
39
|
+
puts Image_Error unless system("#{Yac::CONFIG["image_edit_command"]||'gimp'} \"#{file}\" 2>/dev/null")
|
25
40
|
else
|
26
|
-
|
41
|
+
edit_text(file)
|
27
42
|
end
|
28
43
|
end
|
29
44
|
|
30
|
-
def
|
31
|
-
|
45
|
+
def edit_text(file)
|
46
|
+
prepare_dir(file)
|
47
|
+
puts Doc_Error unless system("#{Yac::CONFIG["editor"] || ENV['EDITOR'] ||'vim'} \"#{file}\" 2>/dev/null")
|
32
48
|
end
|
33
49
|
|
34
|
-
def
|
35
|
-
f
|
50
|
+
def clean_filename(f)
|
51
|
+
return f.sub(/^(.*)?(main|private)\/(.*)/,'\3').sub(/^@/,'')
|
36
52
|
end
|
37
53
|
|
38
54
|
def colorful(stuff,level="text",line_break = true)
|
@@ -42,15 +58,13 @@ module Format
|
|
42
58
|
end
|
43
59
|
|
44
60
|
def empha(stuff,level="text",empha_regexp=/(@@@(.*)@@@)/)
|
45
|
-
stuff.scan(empha_regexp) do |x|
|
61
|
+
stuff.to_s.scan(empha_regexp) do |x|
|
46
62
|
return stuff.gsub(x[0],"\033[0m\033[#{Yac::CONFIG["empha"].to_s}m%s\033[0m\033[%sm" % [x[1],Yac::CONFIG[level]])
|
47
63
|
end
|
48
64
|
end
|
49
65
|
|
50
|
-
def
|
51
|
-
|
52
|
-
|
53
|
-
colorful(@all_result.join("\s"*2),"possible_result_content")
|
54
|
-
end
|
66
|
+
def prepare_dir(file)
|
67
|
+
dirseparator = file.rindex(File::Separator)+1
|
68
|
+
FileUtils.mkdir_p(file[0,dirseparator])
|
55
69
|
end
|
56
70
|
end
|
data/lib/yac.rb
CHANGED
@@ -6,8 +6,11 @@ module Yac
|
|
6
6
|
extend self
|
7
7
|
|
8
8
|
YACRC = File.join("#{ENV['HOME']}",".yacrc")
|
9
|
+
|
9
10
|
FileUtils.cp(File.join(File.dirname(__FILE__), "..","resources","yacrc"), YACRC) unless File.exist?(YACRC)
|
11
|
+
|
10
12
|
CONFIG = YAML.load_file(File.join(ENV['HOME'],".yacrc"))
|
13
|
+
|
11
14
|
CONFIG["root"] ||= File.join(ENV['HOME'],".yac")
|
12
15
|
|
13
16
|
@main_path, @pri_path = File.join(CONFIG["root"],"/main/"), File.join(CONFIG["root"],"/private/")
|
@@ -15,41 +18,39 @@ module Yac
|
|
15
18
|
@pri_git = Git.open(@pri_path)if File.exist?(@pri_path)
|
16
19
|
|
17
20
|
def new(args)
|
18
|
-
unless File.exist?(@main_path) && File.exist?(@pri_path)
|
19
|
-
return unless init
|
20
|
-
end
|
21
|
-
@all_result = []
|
21
|
+
init unless File.exist?(@main_path) && File.exist?(@pri_path)
|
22
22
|
(help && exit) if args.empty?
|
23
23
|
case args.first
|
24
24
|
when "show" then show(args[1,args.size])
|
25
|
-
when "
|
26
|
-
when "content" then search(args[1,args.size],"content")
|
25
|
+
when "search" then search(args[1,args.size])
|
27
26
|
when "update" then update(args[1,args.size])
|
28
|
-
when
|
27
|
+
when "push" then push(args[1,args.size])
|
28
|
+
when "add" then add(args[1,args.size])
|
29
|
+
when "edit" then edit(args[1,args.size])
|
29
30
|
when /^(help|-h|yac|--help)$/ then help
|
30
|
-
when
|
31
|
+
when "sh" then shell(args[1,args.size])
|
31
32
|
when "rm" then rm(args[1,args.size])
|
32
|
-
when "
|
33
|
+
when "mv" then rename(args[1,args.size])
|
34
|
+
when /^version|-v$/ then
|
35
|
+
load File.join(File.dirname(__FILE__), "..", "yac.gemspec");colorful("yac, version: " + VER,"notice")
|
33
36
|
else show(args)
|
34
37
|
end
|
35
|
-
show_possible_result
|
36
38
|
rescue
|
37
39
|
end
|
38
40
|
|
39
41
|
def init
|
40
42
|
FileUtils.mkdir_p(CONFIG['root'])
|
41
43
|
{"main" => @main_path,"private" => @pri_path}.each do |name,path|
|
42
|
-
|
44
|
+
if File.exist?(path)
|
45
|
+
colorful("#{name} repository has already initialized.","notice")
|
46
|
+
else
|
43
47
|
if CONFIG["#{name}"] && CONFIG["#{name}"]['clone-from']
|
44
|
-
|
48
|
+
colorful("Initialize #{name} repository from #{CONFIG[name]['clone-from']} to #{CONFIG['root']}/#{name}","notice")
|
45
49
|
Git.clone(CONFIG["#{name}"]['clone-from'], name, :path => CONFIG['root'])
|
46
50
|
else
|
47
|
-
|
48
|
-
|
49
|
-
git.add
|
50
|
-
git.commit_all("init #{name} repository")
|
51
|
+
colorful("Initialize #{name} repository from scratch to #{CONFIG['root']}/#{name}","notice")
|
52
|
+
Git.init(path)
|
51
53
|
end
|
52
|
-
puts "#{name} repository initialized."
|
53
54
|
@main_git = Git.open(@main_path) if File.exist?(@main_path)
|
54
55
|
@pri_git = Git.open(@pri_path)if File.exist?(@pri_path)
|
55
56
|
end
|
@@ -60,25 +61,40 @@ module Yac
|
|
60
61
|
args.each {|x| show_single(x)}
|
61
62
|
end
|
62
63
|
|
63
|
-
def search(args
|
64
|
-
args.each {|x|
|
64
|
+
def search(args)
|
65
|
+
args.each {|x| search_content(x)}
|
65
66
|
end
|
66
67
|
|
67
68
|
def update(args)
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
else
|
72
|
-
@main_git.pull && @pri_git.pull
|
69
|
+
case args.to_s
|
70
|
+
when /main/ then result = `cd "#{@main_path}" && git pull ` #NOTE There is an bug in the git.gem,Then I will write a new git library use shell command
|
71
|
+
when /all/ then result = `cd "#{@pri_path}" && git pull && cd "#{@main_path}" && git pull `
|
72
|
+
else result = `cd "#{@pri_path}" && git pull`
|
73
73
|
end
|
74
|
+
colorful(result,"notice")
|
74
75
|
rescue
|
75
|
-
|
76
|
+
colorful("ERROR: can not update the repository,\n\n#{$!}","warn")
|
77
|
+
end
|
78
|
+
|
79
|
+
def push(args)
|
80
|
+
case args.to_s
|
81
|
+
when /main/ then result=@main_git.push
|
82
|
+
when /all/ then result=@pri_git.push && result << @main_git.push
|
83
|
+
else result = @pri_git.push
|
84
|
+
end
|
85
|
+
colorful(result,"notice")
|
86
|
+
rescue
|
87
|
+
colorful("Usage:\nyac push ( main | all )\n\nTry `yac -h` for more help\n\n#{$1}","warn")
|
76
88
|
end
|
77
89
|
|
78
90
|
def edit(args)
|
79
91
|
args.each {|x| edit_single(x)}
|
80
92
|
end
|
81
93
|
|
94
|
+
def add(args)
|
95
|
+
args.each {|x| add_single(x)}
|
96
|
+
end
|
97
|
+
|
82
98
|
def rm(args)
|
83
99
|
args.each {|x| rm_single(x)}
|
84
100
|
end
|
@@ -90,97 +106,146 @@ module Yac
|
|
90
106
|
def shell(args)
|
91
107
|
case args.to_s
|
92
108
|
when /main/
|
93
|
-
colorful(" Welcome To The Main Yac Repository","
|
94
|
-
system "cd #{@main_path}; sh"
|
109
|
+
colorful(" Welcome To The Main Yac Repository","notice")
|
110
|
+
system "cd \"#{@main_path}\"; sh"
|
95
111
|
else
|
96
|
-
colorful(" Welcome To The Private Yac Repository","
|
97
|
-
system "cd #{@pri_path}; sh"
|
112
|
+
colorful(" Welcome To The Private Yac Repository","notice")
|
113
|
+
system "cd \"#{@pri_path}\"; sh"
|
98
114
|
end
|
99
115
|
end
|
100
116
|
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
117
|
+
def rename(args)
|
118
|
+
(colorful("Usage:\nyac mv [orign_name] [new_name]\n\nTry `yac -h` for more help","warn");exit) unless args.size == 2
|
119
|
+
file = search_name(args[0],"Rename")
|
120
|
+
new_name = file.sub(/^((?:.*)?(?:main|private)\/)(.*)(\..*)/,'\1'+args[1]+'\3')
|
121
|
+
if confirm("You Are Renaming #{file} To #{new_name}")
|
122
|
+
`mv "#{file}" "#{new_name}"`
|
123
|
+
@working_git.add
|
124
|
+
@working_git.commit_all("#{clean_filename(file)} Renamed to #{clean_filename(new_name)}")
|
109
125
|
end
|
110
126
|
end
|
111
127
|
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
128
|
+
protected
|
129
|
+
def add_single(args)
|
130
|
+
if args.include?('/') && args =~ /(@?)(?:(.*)\/)(.+)/
|
131
|
+
path = $1.empty? ? @pri_path : @main_path
|
132
|
+
all_path = %x{
|
133
|
+
find #{path} -type d -iwholename '#{path}*#{$2}*' -not -iwholename '*.git*'| sed 's/^.*\\(private\\|main\\)\\//#{$1}/'
|
134
|
+
}.to_a
|
135
|
+
colorful("Which directory do you want to use:","notice")
|
136
|
+
choosed_path = choose_one(all_path.concat([$1+$2]).uniq)
|
137
|
+
args = choosed_path + "/" + $3 if choosed_path
|
138
|
+
end
|
139
|
+
file = full_path(args+".ch")
|
140
|
+
if confirm("You Are Adding #{file}")
|
141
|
+
edit_text(file)
|
142
|
+
@working_git.add
|
143
|
+
@working_git.commit_all("#{clean_filename(file)} Added")
|
144
|
+
end
|
118
145
|
end
|
119
146
|
|
120
147
|
def show_single(args)
|
121
|
-
|
122
|
-
|
123
|
-
colorful(result.first,"filename")
|
124
|
-
format_file(result.first)
|
125
|
-
else
|
126
|
-
result.map do |x|
|
127
|
-
if x =~ /\/#{args.sub(/^@/,"")}\.\w+/
|
128
|
-
colorful(x,"filename")
|
129
|
-
format_file(x)
|
130
|
-
end
|
131
|
-
end
|
132
|
-
end
|
148
|
+
file = search_name(args,"Show")
|
149
|
+
format_file(file)
|
133
150
|
end
|
134
151
|
|
135
|
-
def
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
152
|
+
def rm_single(args)
|
153
|
+
file = search_name(args,"Remove")
|
154
|
+
if confirm("You Are Removing #{file}.")
|
155
|
+
begin
|
156
|
+
@working_git.remove(file)
|
157
|
+
@working_git.commit_all("#{clean_filename(file)} Removed")
|
158
|
+
rescue Git::GitExecuteError
|
159
|
+
FileUtils.rm_rf(file)
|
160
|
+
end
|
140
161
|
end
|
141
162
|
end
|
142
163
|
|
143
|
-
def
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
@main_result = @main_git.ls_files.keys.grep(/#{args}/)
|
150
|
-
end
|
151
|
-
@all_result << @main_result.collect {|x| "@" + x} << @private_result
|
164
|
+
def edit_single(args)
|
165
|
+
file = search_name(args,"Edit")
|
166
|
+
edit_file(file)
|
167
|
+
@working_git.add
|
168
|
+
@working_git.commit_all("#{clean_filename(file)} Updated")
|
169
|
+
end
|
152
170
|
|
153
|
-
|
154
|
-
|
171
|
+
def search_name(args,msg = nil)
|
172
|
+
path = (args =~ /^(@)/) ? [@main_path] : [@main_path , @pri_path]
|
173
|
+
result = []
|
174
|
+
path.each do |x|
|
175
|
+
result.concat(`find "#{x}" -type f -iwholename '#{x}*#{args.sub(/^@/,'').strip}*' -not -iwholename '*.git*'| sed 's/^.*\\(private\\|main\\)\\//#{x=~/main/ ? '@':'' }/'`.to_a)
|
155
176
|
end
|
156
|
-
return
|
177
|
+
return result.empty? ? (colorful("Nothing Found About < #{args} >","warn")) :
|
178
|
+
(colorful("The Results About < #{args} > To #{msg || "Operate"} :","notice");full_path(choose_one(result)))
|
157
179
|
end
|
158
180
|
|
159
181
|
def search_content(args)
|
160
|
-
|
161
|
-
result
|
182
|
+
args.sub!(/^"(.*)"/,'\1')
|
183
|
+
result = `cd "#{@pri_path}" && grep -n -i -P '#{args}' -R *.ch 2>/dev/null`.to_a
|
184
|
+
result.concat(`cd "#{@main_path}" && grep -n -i -P '#{args}' -R *.ch 2>/dev/null | sed 's/^/@/g'`.to_a)
|
185
|
+
all_result = []
|
162
186
|
result.each do |x|
|
163
187
|
stuff = x.split(':',3)
|
164
|
-
colorful(
|
188
|
+
colorful(stuff[0],"filename",false)
|
165
189
|
print " "
|
166
190
|
colorful(stuff[1],"line_number",false)
|
167
191
|
print " "
|
168
|
-
format_section(empha(stuff[2],nil,/((#{args}))/),true)
|
192
|
+
format_section(empha(stuff[2],nil,/((#{args}))/i),true)
|
193
|
+
all_result.concat(stuff[0].to_a)
|
194
|
+
end
|
195
|
+
loop do
|
196
|
+
colorful("All files Contain #{args.strip},Choose one to show","notice")
|
197
|
+
file = full_path(choose_one(all_result))
|
198
|
+
file ? format_file(file) : exit
|
169
199
|
end
|
170
|
-
end
|
171
|
-
|
172
|
-
def prepare_dir
|
173
|
-
dirseparator = @file_path.rindex(File::Separator)+1
|
174
|
-
FileUtils.mkdir_p(@file_path[0,dirseparator])
|
175
200
|
end
|
176
201
|
|
177
202
|
def full_path(args)
|
203
|
+
return false unless args
|
178
204
|
if args =~ /^@/
|
179
|
-
@file_path = @main_path + args.sub(/^@/,"") + ".ch"
|
180
205
|
@working_git = @main_git
|
206
|
+
file = @main_path + args.sub(/^@/,"")
|
181
207
|
else
|
182
|
-
@file_path = @pri_path + args + ".ch"
|
183
208
|
@working_git = @pri_git
|
209
|
+
file = @pri_path + args
|
210
|
+
end
|
211
|
+
return file.strip
|
212
|
+
end
|
213
|
+
|
214
|
+
def confirm(*msg)
|
215
|
+
colorful("#{msg.to_s}\nAre You Sure (Y/N) (q to quit):","notice",false)
|
216
|
+
case STDIN.gets
|
217
|
+
when /n|q/i
|
218
|
+
return false
|
219
|
+
when /y/i
|
220
|
+
return true
|
221
|
+
else
|
222
|
+
colorful("Please Input A Valid String,","warn")
|
223
|
+
confirm(msg)
|
184
224
|
end
|
185
225
|
end
|
226
|
+
|
227
|
+
# Choose one file to operate
|
228
|
+
def choose_one(stuff)
|
229
|
+
if stuff.size == 1
|
230
|
+
return stuff[0]
|
231
|
+
elsif stuff.size > 1
|
232
|
+
stuff.each_index do |x|
|
233
|
+
colorful("%2s" % (x+1).to_s,"line_number",false)
|
234
|
+
printf " %-20s \t" % [stuff[x].rstrip]
|
235
|
+
print "\n" if (x+1)%4 == 0
|
236
|
+
end
|
237
|
+
printf "\n"
|
238
|
+
num = choose_range(stuff.size)
|
239
|
+
return stuff[num-1].to_s.strip
|
240
|
+
end
|
241
|
+
rescue #Rescue for user input q to quit
|
242
|
+
end
|
243
|
+
|
244
|
+
#choose a valid range
|
245
|
+
def choose_range(size)
|
246
|
+
colorful("Please Input A Valid Number To Choose (1..#{size}) (q to quit): ","notice",false)
|
247
|
+
num = STDIN.gets
|
248
|
+
return if num =~ /q/i
|
249
|
+
(1..size).member?(num.to_i) ? (return num.to_i) : choose_range(size)
|
250
|
+
end
|
186
251
|
end
|
data/resources/yacrc
CHANGED
@@ -4,12 +4,14 @@ main:
|
|
4
4
|
clone-from: git://github.com/wosmvp/cheat.git
|
5
5
|
# push-to:
|
6
6
|
private:
|
7
|
-
#
|
8
|
-
#
|
7
|
+
# clone-from:
|
8
|
+
# push-to:
|
9
9
|
|
10
|
-
|
11
|
-
#
|
10
|
+
pdf_command: evince
|
11
|
+
#image_command: eog
|
12
12
|
#editor: vim
|
13
|
+
#pdf_edit_command: ooffice
|
14
|
+
#image_edit_command: gimp
|
13
15
|
|
14
16
|
#Set Color
|
15
17
|
#1 - Change text to hicolor (bold) mode
|
@@ -35,17 +37,17 @@ private:
|
|
35
37
|
#0 - Turn off all attributes.
|
36
38
|
#7 - Change to Black text on a White background
|
37
39
|
|
38
|
-
head1: 31
|
39
|
-
head2:
|
40
|
-
head3: 33
|
41
|
-
head4:
|
42
|
-
head5:
|
43
|
-
head6:
|
44
|
-
head7:
|
40
|
+
head1: 1;31
|
41
|
+
head2: 1;36
|
42
|
+
head3: 1;33
|
43
|
+
head4: 1;32
|
44
|
+
head5: 1;34
|
45
|
+
head6: 1;35
|
46
|
+
head7: 1;37
|
45
47
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
filename:
|
48
|
+
warn: 31
|
49
|
+
notice: 33
|
50
|
+
empha: 31;43
|
51
|
+
filename: 34
|
50
52
|
line_number: 32
|
51
53
|
text:
|
data/yac.gemspec
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
GEM = "yac"
|
2
|
-
VER = "0.
|
3
|
-
DATE = %q{2008-10-
|
2
|
+
VER = "1.0.0"
|
3
|
+
DATE = %q{2008-10-28}
|
4
4
|
AUTHOR = "Jinzhu Zhang"
|
5
5
|
EMAIL = "wosmvp@gmail.com"
|
6
6
|
HOMEPAGE = "http://www.zhangjinzhu.com"
|
7
|
-
SUMMARY = "Yet Another Cheat"
|
7
|
+
SUMMARY = "Yet Another Cheat: sexy command line tool for cheat sheet"
|
8
8
|
|
9
9
|
Gem::Specification.new do |s|
|
10
10
|
|
@@ -25,7 +25,7 @@ Gem::Specification.new do |s|
|
|
25
25
|
s.autorequire = 'yac'
|
26
26
|
s.executables = ["yac"]
|
27
27
|
|
28
|
-
s.files = %w[README.rdoc
|
28
|
+
s.files = %w[README.rdoc yac.gemspec resources/yacrc bin/yac lib/yac.rb lib/format.rb]
|
29
29
|
|
30
30
|
#s.has_rdoc = true
|
31
31
|
s.rdoc_options = ["--quiet", "--title", "YAC => Yet Another Cheat", "--opname", "index.html", "--line-numbers", "--main", "README.rdoc", "--inline-source"]
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wosmvp-yac
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jinzhu Zhang
|
@@ -9,7 +9,7 @@ autorequire: yac
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-10-
|
12
|
+
date: 2008-10-28 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
- !ruby/object:Gem::Version
|
22
22
|
version: 1.0.0
|
23
23
|
version:
|
24
|
-
description: Yet Another Cheat
|
24
|
+
description: "Yet Another Cheat: sexy command line tool for cheat sheet"
|
25
25
|
email: wosmvp@gmail.com
|
26
26
|
executables:
|
27
27
|
- yac
|
@@ -31,7 +31,6 @@ extra_rdoc_files:
|
|
31
31
|
- README.rdoc
|
32
32
|
files:
|
33
33
|
- README.rdoc
|
34
|
-
- README.cn
|
35
34
|
- yac.gemspec
|
36
35
|
- resources/yacrc
|
37
36
|
- bin/yac
|
@@ -70,6 +69,6 @@ rubyforge_project: yac
|
|
70
69
|
rubygems_version: 1.2.0
|
71
70
|
signing_key:
|
72
71
|
specification_version: 2
|
73
|
-
summary: Yet Another Cheat
|
72
|
+
summary: "Yet Another Cheat: sexy command line tool for cheat sheet"
|
74
73
|
test_files: []
|
75
74
|
|
data/README.cn
DELETED
@@ -1,57 +0,0 @@
|
|
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 / -h /--help / yac
|
30
|
-
=== 打开仓库shell
|
31
|
-
$ yac shell / sh main 打开主仓库的shell
|
32
|
-
$ yac shell / sh 打开个人仓库的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
|