yac 1.2.1 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +14 -4
- data/README.rdoc +7 -5
- data/lib/format.rb +36 -22
- data/lib/yac.rb +20 -15
- data/yac.gemspec +1 -1
- metadata +1 -1
data/CHANGELOG
CHANGED
@@ -1,12 +1,22 @@
|
|
1
|
-
|
1
|
+
=== 1.3.0 / 2008-11-20
|
2
|
+
|
3
|
+
* add office support (odf,odp,ods,uof,doc...)
|
4
|
+
* words wrapped by @ to highlight
|
5
|
+
* Fix some minor bug.
|
6
|
+
|
7
|
+
=== 1.2.0 / 2008-11-18
|
8
|
+
|
2
9
|
* modify all commands search => -S , add => -a ,edit => -e and so on
|
3
|
-
|
10
|
+
|
11
|
+
=== 1.1.1 / 2008-11-8
|
12
|
+
|
4
13
|
* $ yac l/oo/t To choose linux/gentoo/install
|
5
14
|
* $ yac add l/oo/t To choose linux/gentoo/ As the directory for file t
|
6
15
|
|
7
|
-
|
16
|
+
=== 1.1.0 / 2008-11-8
|
17
|
+
|
8
18
|
* Don't need schacon-git anymore
|
9
19
|
* When Choose files You can Just press enter to choose the first one
|
10
20
|
* When Confirm You can Just press enter to answer Yes
|
11
21
|
|
12
|
-
Version
|
22
|
+
Version previous 1.1.0 Please See README
|
data/README.rdoc
CHANGED
@@ -1,5 +1,5 @@
|
|
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
|
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!!!@
|
3
3
|
|
4
4
|
== What?
|
5
5
|
Cheat sheet is a concise set of notes used for quick reference.
|
@@ -38,9 +38,10 @@
|
|
38
38
|
$ yac -r [cheatsheet] (Sure,you can use *)
|
39
39
|
|
40
40
|
=== Search all sheets
|
41
|
-
$ yac -S [keyword] (
|
41
|
+
$ yac -S [keyword] (@Take Attention:@ You are allowed to use perl-like Regex)
|
42
42
|
Eg:
|
43
43
|
$ yac -S lin.*x
|
44
|
+
$ yac -S '\$:' To Search $:
|
44
45
|
And Even:
|
45
46
|
$ yac -S "r(uby|ails)"
|
46
47
|
|
@@ -64,15 +65,16 @@
|
|
64
65
|
=== Help (display this file)
|
65
66
|
$ yac -h
|
66
67
|
|
68
|
+
=== Version
|
69
|
+
$ yac -v
|
70
|
+
|
67
71
|
=== Documents format
|
68
72
|
All text file add ".ch" as suffix for butter editor highlight
|
69
73
|
(A very very simple vim script can be found here : http://www.vim.org/scripts/script.php?script_id=2399)
|
70
74
|
|
71
75
|
At the beginning of the row,plus N = for the N-class title
|
72
76
|
|
73
|
-
|
74
|
-
|
75
|
-
Words wrapped by three @ for highlight
|
77
|
+
Words wrapped by @ for highlight
|
76
78
|
|
77
79
|
=== The configure file
|
78
80
|
Default use $HOME/.yacrc , See the example file under resources directory
|
data/lib/format.rb
CHANGED
@@ -7,50 +7,65 @@ end
|
|
7
7
|
module Format
|
8
8
|
Pdf_Error = "Please Modify ~/.yacrc To Provide A Valid Command To Operate PDF Document"
|
9
9
|
Image_Error = "Please Modify ~/.yacrc To Provide A Valid Command To Operate Image Document"
|
10
|
+
Office_Error = "Please Modify ~/.yacrc To Provide A Valid Command To Operate Office Document"
|
10
11
|
Doc_Error = "Please Modify ~/.yacrc To Provide A Valid Command To Operate Text Document"
|
11
12
|
|
12
13
|
def format_file(file)
|
13
|
-
@level = 0
|
14
14
|
colorful(file,"filename") if file
|
15
15
|
case `file "#{file}" 2>/dev/null`
|
16
16
|
when / PDF document/
|
17
|
-
puts Pdf_Error unless system("#{Yac::CONFIG["pdf_command"]||'evince'}
|
17
|
+
puts Pdf_Error unless system("#{Yac::CONFIG["pdf_command"]||'evince'} '#{file}' 2>/dev/null")
|
18
18
|
when /( image )|(\.svg)/
|
19
|
-
puts Image_Error unless system("#{Yac::CONFIG["image_command"]||'eog'}
|
19
|
+
puts Image_Error unless system("#{Yac::CONFIG["image_command"]||'eog'} '#{file}' 2>/dev/null")
|
20
|
+
when /Office Document/
|
21
|
+
open_office(file)
|
20
22
|
else
|
21
|
-
File.
|
22
|
-
|
23
|
+
if File.extname(file) =~ /^\.(od[tfspg]|uof)$/ #Support odf uof ods odp...
|
24
|
+
open_office(file)
|
25
|
+
else
|
26
|
+
File.new(file).each do |x|
|
27
|
+
format_section(x)
|
28
|
+
end
|
23
29
|
end
|
24
30
|
end
|
25
|
-
rescue
|
26
31
|
end
|
27
32
|
|
28
|
-
def format_section(section,
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
colorful(section.sub(/^\s*/,'')) if search
|
33
|
+
def format_section(section,empha_regexp = false)
|
34
|
+
if section =~ /^(=+)\s+(.*)/
|
35
|
+
level,stuff = $1.size,$2
|
36
|
+
# Highlight the keyword when searching
|
37
|
+
stuff = empha(stuff,"head#{level}",empha_regexp) if empha_regexp
|
38
|
+
colorful("\s"*(level-1) + stuff,"head#{level}")
|
35
39
|
else
|
36
|
-
|
40
|
+
section = empha(section,"text",empha_regexp) if empha_regexp
|
41
|
+
colorful(section)
|
37
42
|
end
|
38
43
|
end
|
39
44
|
|
40
45
|
def edit_file(file)
|
41
46
|
case `file "#{file}" 2>/dev/null`
|
42
47
|
when / PDF /
|
43
|
-
puts Pdf_Error unless system("#{Yac::CONFIG["pdf_edit_command"]||'ooffice'}
|
48
|
+
puts Pdf_Error unless system("#{Yac::CONFIG["pdf_edit_command"]||'ooffice'} '#{file}' 2>/dev/null")
|
44
49
|
when /( image )|(\.svg)/
|
45
|
-
puts Image_Error unless system("#{Yac::CONFIG["image_edit_command"]||'gimp'}
|
50
|
+
puts Image_Error unless system("#{Yac::CONFIG["image_edit_command"]||'gimp'} '#{file}' 2>/dev/null")
|
51
|
+
when /Office Document/
|
52
|
+
open_office(file)
|
46
53
|
else
|
47
|
-
|
54
|
+
if File.extname(file) =~ /^\.(od[tfspg]|uof)$/ #Support odf uof ods odp...
|
55
|
+
open_office(file)
|
56
|
+
else
|
57
|
+
edit_text(file)
|
58
|
+
end
|
48
59
|
end
|
49
60
|
end
|
50
61
|
|
62
|
+
def open_office(file)
|
63
|
+
puts Office_Error unless system("#{Yac::CONFIG["office_command"]||'ooffice'} '#{file}' 2>/dev/null")
|
64
|
+
end
|
65
|
+
|
51
66
|
def edit_text(file)
|
52
67
|
prepare_dir(file)
|
53
|
-
puts Doc_Error unless system("#{Yac::CONFIG["editor"] || ENV['EDITOR'] ||'vim'}
|
68
|
+
puts Doc_Error unless system("#{Yac::CONFIG["editor"] || ENV['EDITOR'] ||'vim'} '#{file}' 2>/dev/null")
|
54
69
|
end
|
55
70
|
|
56
71
|
def colorful(stuff,level="text",line_break = true)
|
@@ -59,14 +74,13 @@ module Format
|
|
59
74
|
print "\n" if line_break
|
60
75
|
end
|
61
76
|
|
62
|
-
def empha(stuff,level="text",empha_regexp=/(
|
77
|
+
def empha(stuff,level="text",empha_regexp=/(@(.*)@)/)
|
63
78
|
stuff.to_s.scan(empha_regexp) do |x|
|
64
|
-
return stuff.gsub(x[0],"\e[0m\e[#{Yac::CONFIG["empha"]
|
79
|
+
return stuff.gsub(x[0],"\e[0m\e[#{Yac::CONFIG["empha"]}m%s\e[0m\e[%sm" % [x[1],Yac::CONFIG[level]])
|
65
80
|
end
|
66
81
|
end
|
67
82
|
|
68
83
|
def prepare_dir(file)
|
69
|
-
|
70
|
-
FileUtils.mkdir_p(file[0,dirseparator])
|
84
|
+
FileUtils.mkdir_p(File.dirname(file))
|
71
85
|
end
|
72
86
|
end
|
data/lib/yac.rb
CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH << File.dirname(__FILE__)
|
|
4
4
|
module Yac
|
5
5
|
include Format
|
6
6
|
extend self
|
7
|
-
VERSION = '1.
|
7
|
+
VERSION = '1.3.0'
|
8
8
|
YACRC = File.join("#{ENV['HOME']}",".yacrc")
|
9
9
|
|
10
10
|
FileUtils.cp(File.join(File.dirname(__FILE__), "..","resources","yacrc"), YACRC) unless File.exist?(YACRC)
|
@@ -34,7 +34,6 @@ module Yac
|
|
34
34
|
when "-v" then colorful("Yac Version: #{Yac::VERSION}",'notice')
|
35
35
|
else show(args)
|
36
36
|
end
|
37
|
-
rescue
|
38
37
|
end
|
39
38
|
|
40
39
|
def init
|
@@ -112,10 +111,10 @@ module Yac
|
|
112
111
|
case args.to_s
|
113
112
|
when /main/
|
114
113
|
colorful(" Welcome To The Main Yac Repository","notice")
|
115
|
-
system "cd
|
114
|
+
system "cd '#{@main_path}'; sh"
|
116
115
|
else
|
117
116
|
colorful(" Welcome To The Private Yac Repository","notice")
|
118
|
-
system "cd
|
117
|
+
system "cd '#{@pri_path}'; sh"
|
119
118
|
end
|
120
119
|
end
|
121
120
|
|
@@ -173,32 +172,38 @@ module Yac
|
|
173
172
|
|
174
173
|
def edit_single(args)
|
175
174
|
file = search_name(args,"Edit")
|
176
|
-
|
177
|
-
|
175
|
+
if file
|
176
|
+
edit_file(file)
|
177
|
+
@working_git.edit(file)
|
178
|
+
end
|
178
179
|
end
|
179
180
|
|
180
181
|
def search_name(args,msg = nil)
|
181
182
|
path = (args =~ /^(@)/) ? [@main_path] : [@main_path , @pri_path]
|
182
183
|
result = []
|
183
184
|
path.each do |x|
|
184
|
-
result.concat(`find "#{x}" -type f -iwholename '#{x}*#{args.gsub(/\//,'*/*').sub(/^@/,'').strip}*' -not -iwholename '
|
185
|
+
result.concat(`find "#{x}" -type f -iwholename '#{x}*#{args.gsub(/\//,'*/*').sub(/^@/,'').strip}*' -not -iwholename '*\/.git\/*'| sed 's/^.*\\/\\(private\\|main\\)\\//#{x=~/main/ ? '@':'' }/'`.to_a)
|
185
186
|
end
|
186
187
|
|
187
|
-
|
188
|
-
|
188
|
+
if result.empty?
|
189
|
+
colorful("Nothing Found About < #{args} >","warn")
|
190
|
+
return false
|
191
|
+
else
|
192
|
+
colorful("The Results About < #{args} > To #{msg} :","notice")
|
193
|
+
return full_path(choose_one(result))
|
194
|
+
end
|
189
195
|
end
|
190
196
|
|
191
197
|
def search_content(args)
|
192
|
-
result = `find "#{@pri_path}" -iname '*.ch' -not -iwholename '
|
193
|
-
result.concat(`find "#{@main_path}" -iname '*.ch' -not -iwholename '
|
198
|
+
result = `find "#{@pri_path}" -iname '*.ch' -not -iwholename '*\/.git\/*' -exec grep -HniP '#{args}' '{}' \\;`.to_a
|
199
|
+
result.concat(`find "#{@main_path}" -iname '*.ch' -not -iwholename '*\/.git\/*' -exec grep -HniP '#{args}' '{}' \\; | sed 's/^/@/g'`.to_a)
|
194
200
|
all_result = []
|
195
201
|
result.each do |x|
|
196
202
|
stuff = x.split(':',3)
|
197
|
-
|
198
|
-
colorful(filename,"filename",false)
|
203
|
+
colorful(File.basename(stuff[0]).sub(/\..*/,''),"filename",false)
|
199
204
|
colorful(stuff[1],"line_number",false)
|
200
|
-
format_section(
|
201
|
-
all_result.
|
205
|
+
format_section(stuff[2],/((#{args}))/i)
|
206
|
+
all_result << stuff[0].sub(/(@?).*\/(?:main|private)\/(.*)/,'\1'+'\2')
|
202
207
|
end
|
203
208
|
all_result.uniq!
|
204
209
|
loop do
|
data/yac.gemspec
CHANGED