wosmvp-yac 1.0.4 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +10 -0
- data/README.rdoc +5 -2
- data/lib/format.rb +8 -6
- data/lib/git.rb +41 -0
- data/lib/yac.rb +35 -56
- data/yac.gemspec +2 -2
- metadata +3 -1
data/CHANGELOG
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
V1.1.1 <2008-11-8>
|
2
|
+
* $ yac l/oo/t To choose linux/gentoo/install
|
3
|
+
* $ yac add l/oo/t To choose linux/gentoo/ As the directory for file t
|
4
|
+
|
5
|
+
V1.1.0 <2008-11-8>
|
6
|
+
* Don't need schacon-git anymore
|
7
|
+
* When Choose files You can Just press enter to choose the first one
|
8
|
+
* When Confirm You can Just press enter to answer Yes
|
9
|
+
|
10
|
+
Version Below V1.1.0 Please See README
|
data/README.rdoc
CHANGED
@@ -9,7 +9,7 @@
|
|
9
9
|
|
10
10
|
== Install
|
11
11
|
Make sure you have ruby,git in your system . then:
|
12
|
-
$ (sudo) gem install yac
|
12
|
+
$ (sudo) gem install yac
|
13
13
|
|
14
14
|
== How To Use
|
15
15
|
|
@@ -20,6 +20,7 @@
|
|
20
20
|
$ yac (show) [cheatsheet] ( you can use * for any chars)
|
21
21
|
Eg:
|
22
22
|
$ yac show lin*x
|
23
|
+
$ yac show l/o/a To show linux/gentoo/masked
|
23
24
|
|
24
25
|
=== To edit a cheat sheet
|
25
26
|
$ yac edit [cheatsheet] (Yes,you can use * for any chars also,then choose one to edit)
|
@@ -30,6 +31,8 @@
|
|
30
31
|
$ yac li*x/install
|
31
32
|
Then will display all directories match /li*x/,feel freely to choose one of them,
|
32
33
|
A new file named install.ch will be added to the directory!
|
34
|
+
$ yac l/oo/install
|
35
|
+
Oh,no,you can choose linux/gentoo as the directory for the install file
|
33
36
|
|
34
37
|
=== To rm a cheat sheet
|
35
38
|
$ yac rm [cheatsheet] (Sure,you can use *)
|
@@ -82,8 +85,8 @@
|
|
82
85
|
|
83
86
|
== REQUIREMENTS:
|
84
87
|
* Ruby
|
88
|
+
* Git
|
85
89
|
* rubygems
|
86
|
-
* git
|
87
90
|
|
88
91
|
== LICENSE:
|
89
92
|
|
data/lib/format.rb
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
class Symbol
|
2
|
+
def to_proc
|
3
|
+
Proc.new { |*args| args.shift.__send__(self, *args) }
|
4
|
+
end
|
5
|
+
end
|
6
|
+
|
1
7
|
module Format
|
2
8
|
Pdf_Error = "Please Modify ~/.yacrc To Provide A Valid Command To Operate PDF Document"
|
3
9
|
Image_Error = "Please Modify ~/.yacrc To Provide A Valid Command To Operate Image Document"
|
@@ -47,19 +53,15 @@ module Format
|
|
47
53
|
puts Doc_Error unless system("#{Yac::CONFIG["editor"] || ENV['EDITOR'] ||'vim'} \"#{file}\" 2>/dev/null")
|
48
54
|
end
|
49
55
|
|
50
|
-
def clean_filename(f)
|
51
|
-
return f.sub(/^(.*)?(main|private)\/(.*)/,'\3').sub(/^@/,'')
|
52
|
-
end
|
53
|
-
|
54
56
|
def colorful(stuff,level="text",line_break = true)
|
55
57
|
stuff = empha(stuff,level)
|
56
|
-
print "\
|
58
|
+
print "\e[%sm%s\e[0m " % [Yac::CONFIG[level],stuff.rstrip]
|
57
59
|
print "\n" if line_break
|
58
60
|
end
|
59
61
|
|
60
62
|
def empha(stuff,level="text",empha_regexp=/(@@@(.*)@@@)/)
|
61
63
|
stuff.to_s.scan(empha_regexp) do |x|
|
62
|
-
return stuff.gsub(x[0],"\
|
64
|
+
return stuff.gsub(x[0],"\e[0m\e[#{Yac::CONFIG["empha"].to_s}m%s\e[0m\e[%sm" % [x[1],Yac::CONFIG[level]])
|
63
65
|
end
|
64
66
|
end
|
65
67
|
|
data/lib/git.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
class Git
|
2
|
+
def initialize(path)
|
3
|
+
@working_path = path
|
4
|
+
end
|
5
|
+
|
6
|
+
def self.clone(from,path,name)
|
7
|
+
`cd #{path} && git clone #{from} #{name}`
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.init(path)
|
11
|
+
`cd #{path} && git init`
|
12
|
+
end
|
13
|
+
|
14
|
+
def mv(orig,new,with_commit = true)
|
15
|
+
`cd '#@working_path' && git mv #{orig} #{new}`
|
16
|
+
self.commit("#{clean_name(orig)} Renamed to #{clean_name(new)}") if with_commit
|
17
|
+
end
|
18
|
+
|
19
|
+
def add(file,with_commit = true)
|
20
|
+
`cd '#@working_path' && git add file`
|
21
|
+
self.commit("#{clean_name(file)} Added") if with_commit
|
22
|
+
end
|
23
|
+
|
24
|
+
def edit(file,with_commit = true)
|
25
|
+
`cd '#@working_path' && git add file`
|
26
|
+
self.commit("#{clean_name(file)} Updated") if with_commit
|
27
|
+
end
|
28
|
+
|
29
|
+
def rm(file,with_commit=true)
|
30
|
+
`cd '#@working_path' && git rm -f file`
|
31
|
+
self.commit("#{clean_name(file)} Removed") if with_commit
|
32
|
+
end
|
33
|
+
|
34
|
+
def commit(msg,*args)
|
35
|
+
`cd '#@working_path' && git commit #{args.to_s} -m '#{msg}'`
|
36
|
+
end
|
37
|
+
|
38
|
+
def clean_name(f)
|
39
|
+
return f.sub(/^(.*)?\/(main|private)\/(.*)/,'\3').sub(/^@/,'')
|
40
|
+
end
|
41
|
+
end
|
data/lib/yac.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
$:.unshift File.dirname(__FILE__)
|
2
|
-
%w(
|
3
|
-
|
2
|
+
%w(git fileutils yaml format).each {|f| require f}
|
4
3
|
module Yac
|
5
4
|
include Format
|
6
5
|
extend self
|
@@ -14,8 +13,8 @@ module Yac
|
|
14
13
|
CONFIG["root"] ||= File.join(ENV['HOME'],".yac")
|
15
14
|
|
16
15
|
@main_path, @pri_path = File.join(CONFIG["root"],"/main/"), File.join(CONFIG["root"],"/private/")
|
17
|
-
@main_git = Git.
|
18
|
-
@pri_git = Git.
|
16
|
+
@main_git = Git.new(@main_path)
|
17
|
+
@pri_git = Git.new(@pri_path)
|
19
18
|
|
20
19
|
def new(args)
|
21
20
|
init unless File.exist?(@main_path) && File.exist?(@pri_path)
|
@@ -47,13 +46,12 @@ module Yac
|
|
47
46
|
else
|
48
47
|
if CONFIG["#{name}"] && CONFIG["#{name}"]['clone-from']
|
49
48
|
colorful("Initialize #{name} repository from #{CONFIG[name]['clone-from']} to #{CONFIG['root']}/#{name}","notice")
|
50
|
-
Git.clone(CONFIG["#{name}"]['clone-from'],
|
49
|
+
Git.clone(CONFIG["#{name}"]['clone-from'],CONFIG['root'],name)
|
51
50
|
else
|
52
51
|
colorful("Initialize #{name} repository from scratch to #{CONFIG['root']}/#{name}","notice")
|
52
|
+
prepare_dir(path)
|
53
53
|
Git.init(path)
|
54
54
|
end
|
55
|
-
@main_git = Git.open(@main_path) if File.exist?(@main_path)
|
56
|
-
@pri_git = Git.open(@pri_path)if File.exist?(@pri_path)
|
57
55
|
end
|
58
56
|
end
|
59
57
|
end
|
@@ -128,35 +126,36 @@ module Yac
|
|
128
126
|
#You can use $ yac mv linux.ch linux/ to rename linux.ch to linux/linux.ch
|
129
127
|
new_filename = args[1].sub(/\/$/,file.sub(/.*\/(.*)(\..*)/,'/\1')).sub(/^(@)?/,file =~ /^#{@main_path}/ ? "@":"")
|
130
128
|
new_name = add_file(new_filename ,file.sub(/.*(\..*)/,'\1'))
|
131
|
-
if confirm("You Are Renaming #{file} To #{new_name}")
|
129
|
+
if new_name && confirm("You Are Renaming #{file} To #{new_name}")
|
132
130
|
prepare_dir(new_name)
|
133
|
-
|
134
|
-
@working_git.add
|
135
|
-
@working_git.commit_all("#{clean_filename(file)} Renamed to #{clean_filename(new_name)}")
|
131
|
+
@working_git.mv(file,new_name)
|
136
132
|
end
|
137
133
|
end
|
138
134
|
|
139
135
|
protected
|
140
136
|
def add_single(args)
|
141
137
|
file = add_file(args)
|
142
|
-
if confirm("You Are Adding #{file}")
|
138
|
+
if file && confirm("You Are Adding #{file}")
|
143
139
|
edit_text(file)
|
144
|
-
@working_git.add
|
145
|
-
@working_git.commit_all("#{clean_filename(file)} Added")
|
140
|
+
@working_git.add(file)
|
146
141
|
end
|
147
142
|
end
|
148
143
|
|
149
144
|
def add_file(args,suffix = ".ch")
|
150
|
-
if args.include?('/') && args =~ /(@?)(?:(.*)\/)(.+)/
|
151
|
-
|
145
|
+
if args.include?('/') && args =~ /(@?)(?:(.*)\/)(.+)/ #choose directory
|
146
|
+
prefix,path_name,file_name = $1,$2,$3
|
147
|
+
path = prefix.empty? ? @pri_path : @main_path #choose git path
|
148
|
+
# Yes,you can use 'l/e' to choose 'linux/gentoo'
|
152
149
|
all_path = %x{
|
153
|
-
find #{path} -type d -iwholename '#{path}*#{
|
154
|
-
}.to_a
|
155
|
-
|
156
|
-
|
157
|
-
|
150
|
+
find #{path} -type d -iwholename '#{path}*#{path_name.gsub(/\//,'*/*')}*' -not -iwholename '*.git*'| sed 's/^.*\\/\\(private\\|main\\)\\//#{prefix}/'
|
151
|
+
}.to_a.map(&:strip).concat([prefix+path_name]).uniq
|
152
|
+
|
153
|
+
colorful("Which directory do you want to use:","notice")
|
154
|
+
choosed_path = choose_one(all_path)
|
155
|
+
return full_path(choosed_path + "/" + file_name + suffix) if choosed_path
|
156
|
+
else
|
157
|
+
return full_path(args+suffix)
|
158
158
|
end
|
159
|
-
file = full_path(args+suffix)
|
160
159
|
end
|
161
160
|
|
162
161
|
def show_single(args)
|
@@ -169,53 +168,43 @@ module Yac
|
|
169
168
|
def rm_single(args)
|
170
169
|
file = search_name(args,"Remove")
|
171
170
|
if confirm("You Are Removing #{file}.")
|
172
|
-
|
173
|
-
@working_git.remove(file)
|
174
|
-
@working_git.commit_all("#{clean_filename(file)} Removed")
|
175
|
-
rescue Git::GitExecuteError
|
176
|
-
FileUtils.rm_rf(file)
|
177
|
-
end
|
171
|
+
@working_git.rm(file)
|
178
172
|
end
|
179
173
|
end
|
180
174
|
|
181
175
|
def edit_single(args)
|
182
176
|
file = search_name(args,"Edit")
|
183
177
|
edit_file(file)
|
184
|
-
@working_git.
|
185
|
-
@working_git.commit_all("#{clean_filename(file)} Updated")
|
178
|
+
@working_git.edit(file)
|
186
179
|
end
|
187
180
|
|
188
181
|
def search_name(args,msg = nil)
|
189
182
|
path = (args =~ /^(@)/) ? [@main_path] : [@main_path , @pri_path]
|
190
183
|
result = []
|
191
184
|
path.each do |x|
|
192
|
-
result.concat(`find "#{x}" -type f -iwholename '#{x}*#{args.sub(/^@/,'').strip}*' -not -iwholename '*.git*'| sed 's
|
185
|
+
result.concat(`find "#{x}" -type f -iwholename '#{x}*#{args.gsub(/\//,'*/*').sub(/^@/,'').strip}*' -not -iwholename '*.git*'| sed 's/^.*\\/\\(private\\|main\\)\\//#{x=~/main/ ? '@':'' }/'`.to_a)
|
193
186
|
end
|
194
|
-
#For loop show filename
|
195
|
-
(format_file(full_path(result[0]));return nil) if msg =~ /show/i && result.size == 1
|
196
187
|
|
197
188
|
return result.empty? ? (colorful("Nothing Found About < #{args} >","warn")) :
|
198
189
|
(colorful("The Results About < #{args} > To #{msg || "Operate"} :","notice");full_path(choose_one(result)))
|
199
190
|
end
|
200
191
|
|
201
192
|
def search_content(args)
|
202
|
-
args.sub!(/^"(.*)"/,'\1')
|
193
|
+
args.sub!(/^"(.*)"/,'\1') #Remove the " for input Regex
|
203
194
|
result = `cd "#{@pri_path}" && grep -n -i -P '#{args}' -R *.ch 2>/dev/null`.to_a
|
204
195
|
result.concat(`cd "#{@main_path}" && grep -n -i -P '#{args}' -R *.ch 2>/dev/null | sed 's/^/@/g'`.to_a)
|
205
196
|
all_result = []
|
206
197
|
result.each do |x|
|
207
198
|
stuff = x.split(':',3)
|
208
199
|
colorful(stuff[0],"filename",false)
|
209
|
-
print " "
|
210
200
|
colorful(stuff[1],"line_number",false)
|
211
|
-
print " "
|
212
201
|
format_section(empha(stuff[2],nil,/((#{args}))/i),true)
|
213
202
|
all_result.concat(stuff[0].to_a)
|
214
203
|
end
|
215
204
|
all_result.uniq!
|
216
205
|
loop do
|
217
|
-
all_result.size > 1 ? (file = full_path(choose_one(all_result))) : (format_file(full_path(all_result[0]));break)
|
218
206
|
colorful("All files Contain #{args.strip},Choose one to show","notice")
|
207
|
+
file = full_path(choose_one(all_result))
|
219
208
|
file ? format_file(file) : break
|
220
209
|
end
|
221
210
|
end
|
@@ -234,39 +223,29 @@ module Yac
|
|
234
223
|
|
235
224
|
def confirm(*msg)
|
236
225
|
colorful("#{msg.to_s}\nAre You Sure (Y/N) (q to quit):","notice",false)
|
237
|
-
|
238
|
-
when /n|q/i
|
239
|
-
return false
|
240
|
-
when /y/i
|
241
|
-
return true
|
242
|
-
else
|
243
|
-
colorful("Please Input A Valid String,","warn")
|
244
|
-
confirm(msg)
|
245
|
-
end
|
226
|
+
return STDIN.gets.to_s =~ /n|q/i ? false : true
|
246
227
|
end
|
247
228
|
|
248
|
-
# Choose one file to operate
|
249
229
|
def choose_one(stuff)
|
250
|
-
if stuff.size
|
251
|
-
return stuff[0]
|
252
|
-
elsif stuff.size > 1
|
230
|
+
if stuff.size > 0
|
253
231
|
stuff.each_index do |x|
|
254
232
|
colorful("%2s" % (x+1).to_s,"line_number",false)
|
255
|
-
printf "
|
256
|
-
print "\n" if (x+1)%
|
233
|
+
printf "%-22s\t" % [stuff[x].rstrip]
|
234
|
+
print "\n" if (x+1)%3 == 0
|
257
235
|
end
|
258
236
|
printf "\n"
|
259
237
|
num = choose_range(stuff.size)
|
260
|
-
return stuff[num-1].to_s.strip
|
238
|
+
return stuff[num-1].to_s.strip #return the filename
|
261
239
|
end
|
262
240
|
rescue #Rescue for user input q to quit
|
263
241
|
end
|
264
242
|
|
265
|
-
#choose a valid
|
243
|
+
#choose a valid number
|
266
244
|
def choose_range(size)
|
267
245
|
colorful("Please Input A Valid Number To Choose (1..#{size}) (q to quit): ","notice",false)
|
268
246
|
num = STDIN.gets
|
269
|
-
return if num =~ /q/i
|
270
|
-
|
247
|
+
return false if num =~ /q/i
|
248
|
+
choosed_num = num.strip.empty? ? 1 : num.to_i
|
249
|
+
(1..size).member?(choosed_num) ? (return choosed_num) : choose_range(size)
|
271
250
|
end
|
272
251
|
end
|
data/yac.gemspec
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
GEM = "yac"
|
2
|
-
VER = "1.
|
2
|
+
VER = "1.1.1"
|
3
3
|
DATE = %q{2008-10-28}
|
4
4
|
AUTHOR = "Jinzhu Zhang"
|
5
5
|
EMAIL = "wosmvp@gmail.com"
|
@@ -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 yac.gemspec resources/yacrc bin/yac lib/yac.rb lib/format.rb]
|
28
|
+
s.files = %w[README.rdoc CHANGELOG yac.gemspec resources/yacrc bin/yac lib/yac.rb lib/format.rb lib/git.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: 1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jinzhu Zhang
|
@@ -31,11 +31,13 @@ extra_rdoc_files:
|
|
31
31
|
- README.rdoc
|
32
32
|
files:
|
33
33
|
- README.rdoc
|
34
|
+
- CHANGELOG
|
34
35
|
- yac.gemspec
|
35
36
|
- resources/yacrc
|
36
37
|
- bin/yac
|
37
38
|
- lib/yac.rb
|
38
39
|
- lib/format.rb
|
40
|
+
- lib/git.rb
|
39
41
|
has_rdoc: false
|
40
42
|
homepage: http://www.zhangjinzhu.com
|
41
43
|
post_install_message:
|