yac 1.3.2 → 1.4.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/CHANGELOG +10 -0
- data/Manifest +2 -2
- data/README.rdoc +31 -44
- data/bin/yac +1 -0
- data/lib/format.rb +28 -57
- data/lib/git.rb +42 -38
- data/lib/symbol.rb +5 -0
- data/lib/yac.rb +146 -137
- data/resources/yacrc +11 -46
- data/yac.gemspec +4 -4
- metadata +6 -4
data/CHANGELOG
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
=== 1.4.0 / 2008-12-28
|
2
|
+
|
3
|
+
* highlight commands,e.g: $ ls
|
4
|
+
* <rename/add> use '@' as prefix will impact the main repository,otherwise private repository
|
5
|
+
* use built-in configure file,if ~/.yacrc doesn't exist
|
6
|
+
* doesn't init empty repository,if havn't provide 'clone-from'
|
7
|
+
* truncate filename when choose for tidiness
|
8
|
+
* if file is empty then delete <edit/add>
|
9
|
+
* ...
|
10
|
+
|
1
11
|
=== 1.3.0 / 2008-11-20
|
2
12
|
|
3
13
|
* add office support (odf,odp,ods,uof,doc...)
|
data/Manifest
CHANGED
data/README.rdoc
CHANGED
@@ -13,79 +13,66 @@
|
|
13
13
|
|
14
14
|
== How To Use
|
15
15
|
|
16
|
-
===
|
17
|
-
|
16
|
+
=== Initialize repositories:
|
17
|
+
$ yac -i
|
18
18
|
|
19
|
-
===
|
20
|
-
|
21
|
-
|
22
|
-
$ yac lin*x
|
23
|
-
$ yac l/o/a
|
19
|
+
=== Show a cheat sheet:
|
20
|
+
$ yac /cheatsheet/ ( * => any chars)
|
21
|
+
E.g:
|
22
|
+
$ yac lin*x => linux linux/welcome
|
23
|
+
$ yac l/o/a => linux/gentoo/masked linux/gentoo/layman
|
24
24
|
|
25
25
|
=== To edit a cheat sheet
|
26
|
-
|
26
|
+
$ yac -e /cheatsheet/ ( * => any chars)
|
27
27
|
|
28
28
|
=== To add a cheat sheet
|
29
|
-
|
30
|
-
|
29
|
+
$ yac -a /cheatsheet/ ( * => any chars)
|
30
|
+
('rename/add' use '@' as prefix will impact the main repository,otherwise private repository)
|
31
|
+
Eg:
|
31
32
|
$ yac -a li*x/install
|
32
|
-
Then will display all directories match /li*x/,feel freely to choose one of them,
|
33
|
-
A new file named install.ch will be added to the directory!
|
34
33
|
$ yac -a l/oo/install
|
35
|
-
Oh,no,you can choose linux/gentoo as the directory for the install file
|
36
34
|
|
37
35
|
=== To rm a cheat sheet
|
38
|
-
|
36
|
+
$ yac -r [cheatsheet] ( * => any chars)
|
39
37
|
|
40
38
|
=== Search all sheets
|
41
|
-
|
42
|
-
|
39
|
+
$ yac -S [keyword] (@Take Attention:@ Perl-like Regexp)
|
40
|
+
Eg:
|
43
41
|
$ yac -S lin.*x
|
44
|
-
$ yac -S '\$:'
|
45
|
-
And Even:
|
42
|
+
$ yac -S '\$:' => To Search $:
|
46
43
|
$ yac -S "r(uby|ails)"
|
47
44
|
|
48
45
|
=== Update repositories
|
49
|
-
|
50
|
-
|
51
|
-
|
46
|
+
$ yac -u main => main repository
|
47
|
+
$ yac -u all => all repositories
|
48
|
+
$ yac -u => private repository
|
52
49
|
|
53
50
|
=== Shell
|
54
|
-
|
55
|
-
|
51
|
+
$ yac -s main => Main repository's shell
|
52
|
+
$ yac -s => Private repository's shell
|
56
53
|
|
57
54
|
== Repository Push
|
58
|
-
|
59
|
-
|
60
|
-
|
55
|
+
$ yac -p main => Main repository
|
56
|
+
$ yac -p all => All repositories
|
57
|
+
$ yac -p => Private repository
|
61
58
|
|
62
59
|
== Rename/mv a cheatsheet:
|
63
|
-
|
60
|
+
$ yac -m [orign_name] [new_name]
|
61
|
+
('rename/add' use '@' as prefix impact the main repository,otherwise private repository)
|
64
62
|
|
65
63
|
=== Help (display this file)
|
66
|
-
|
64
|
+
$ yac -h
|
67
65
|
|
68
66
|
=== Version
|
69
|
-
|
70
|
-
|
71
|
-
=== Documents format
|
72
|
-
All text file add ".ch" as suffix for butter editor highlight
|
73
|
-
(A very very simple vim script can be found here : http://www.vim.org/scripts/script.php?script_id=2399)
|
74
|
-
|
75
|
-
At the beginning of the row,plus N = for the N-class title
|
76
|
-
|
77
|
-
Words wrapped by @ for highlight
|
67
|
+
$ yac -v
|
78
68
|
|
79
69
|
=== The configure file
|
80
|
-
|
81
|
-
|
82
|
-
=== Others
|
83
|
-
Add @ before [keyword] will only affect the main repository
|
70
|
+
<$HOME/.yacrc> OR <Example file under resources directory>
|
84
71
|
|
85
72
|
== REQUIREMENTS:
|
86
73
|
* Ruby
|
87
74
|
* Git
|
88
|
-
*
|
75
|
+
* RubyGems
|
89
76
|
|
90
77
|
== LICENSE:
|
91
78
|
|
@@ -94,5 +81,5 @@ This software is shared by GPL3 License
|
|
94
81
|
Copyright (c) 2008 Jinzhu Zhang
|
95
82
|
|
96
83
|
== BY: Jinzhu Zhang
|
97
|
-
http://www.zhangjinzhu.com
|
98
|
-
wosmvp (no-spam) gmail (no-spam) com
|
84
|
+
http://www.zhangjinzhu.com
|
85
|
+
wosmvp (no-spam) gmail (no-spam) com
|
data/bin/yac
CHANGED
data/lib/format.rb
CHANGED
@@ -1,86 +1,57 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
module Format
|
2
|
+
|
3
|
+
def Error(x)
|
4
|
+
colorful "Please Provide A Valid Command To Operate #{x} (~/.yacrc)",'warn'
|
4
5
|
end
|
5
|
-
end
|
6
6
|
|
7
|
-
|
8
|
-
|
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"
|
11
|
-
Doc_Error = "Please Modify ~/.yacrc To Provide A Valid Command To Operate Text Document"
|
7
|
+
def handle_file(file,action = 'show')
|
8
|
+
colorful(file,"filename")
|
12
9
|
|
13
|
-
def format_file(file)
|
14
|
-
colorful(file,"filename") if file
|
15
10
|
case `file "#{file}" 2>/dev/null`
|
16
11
|
when / PDF document/
|
17
|
-
|
12
|
+
Error('PDF') unless system("#{Yac::CONFIG["#{action}_pdf"]} '#{file}' ")
|
18
13
|
when /( image)|( bitmap)|(\.svg)/
|
19
|
-
|
14
|
+
Error('Image') unless system("#{Yac::CONFIG["#{action}_image"]} '#{file}'")
|
20
15
|
when /Office Document/
|
21
|
-
|
16
|
+
Error('Office') unless system("#{Yac::CONFIG["#{action}_office"]} '#{file}'")
|
22
17
|
else
|
23
|
-
if File.extname(file) =~ /^\.(od[tfspg]|uof)$/ #
|
24
|
-
|
18
|
+
if File.extname(file) =~ /^\.(od[tfspg]|uof)$/ # FileType: odf uof ods odp ...
|
19
|
+
Error('Office') unless system("#{Yac::CONFIG["#{action}_office"]} '#{file}'")
|
25
20
|
else
|
26
|
-
File.new(file).each
|
27
|
-
format_section(x)
|
28
|
-
end
|
21
|
+
action =~ /show/ ? File.new(file).each {|x| format_text(x)} : edit_text(file)
|
29
22
|
end
|
30
23
|
end
|
31
24
|
end
|
32
25
|
|
33
|
-
def
|
34
|
-
|
35
|
-
|
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}")
|
39
|
-
else
|
40
|
-
section = empha(section,"text",empha_regexp) if empha_regexp
|
41
|
-
colorful(section)
|
42
|
-
end
|
26
|
+
def edit_text(file)
|
27
|
+
FileUtils.mkdir_p(File.dirname(file)) # Prepare Directory When Add File
|
28
|
+
Error('Text') unless system("#{Yac::CONFIG["editor"]||ENV['EDITOR']} '#{file}'")
|
43
29
|
end
|
44
30
|
|
45
|
-
def
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
colorful(
|
51
|
-
when /Office Document/
|
52
|
-
open_office(file)
|
31
|
+
def format_text(section,empha_regexp = false)
|
32
|
+
if section =~ /^(=+)\s+(.*)/
|
33
|
+
level,section = $1.size,$2
|
34
|
+
# Highlight keyword when searching
|
35
|
+
section = empha(section,"head#{level}",empha_regexp) if empha_regexp
|
36
|
+
colorful("\s"*(level-1) + section,"head#{level}")
|
53
37
|
else
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
38
|
+
# command or plain text
|
39
|
+
level = (section =~ /^\s*\$\s+/) ? 'shell' : 'text'
|
40
|
+
section.sub!(/^(\s*\$\s+.*)/,"\e[#{@color['shell']}m"+'\1'+"\e[0m")
|
41
|
+
section = empha(section,level,empha_regexp) if empha_regexp
|
42
|
+
colorful(section)
|
59
43
|
end
|
60
44
|
end
|
61
45
|
|
62
|
-
def open_office(file)
|
63
|
-
colorful(Office_Error,'warn') unless system("#{Yac::CONFIG["office_command"]||'ooffice'} '#{file}' 2>/dev/null")
|
64
|
-
end
|
65
|
-
|
66
|
-
def edit_text(file)
|
67
|
-
prepare_dir(file)
|
68
|
-
colorful(Doc_Error,'warn') unless system("#{Yac::CONFIG["editor"] || ENV['EDITOR'] ||'vim'} '#{file}' 2>/dev/null")
|
69
|
-
end
|
70
|
-
|
71
46
|
def colorful(stuff,level="text",line_break = true)
|
72
47
|
stuff = empha(stuff,level)
|
73
|
-
print "\e[%sm%s\e[0m " % [
|
48
|
+
print "\e[%sm%s\e[0m " % [@color[level],stuff.rstrip]
|
74
49
|
print "\n" if line_break
|
75
50
|
end
|
76
51
|
|
77
52
|
def empha(stuff,level="text",empha_regexp=/(@(.*)@)/)
|
78
53
|
stuff.to_s.scan(empha_regexp) do |x|
|
79
|
-
return stuff.gsub(x[0],"\e[0m\e[#{
|
54
|
+
return stuff.gsub(x[0],"\e[0m\e[#{@color["empha"]}m%s\e[0m\e[%sm" % [x[1],@color[level]])
|
80
55
|
end
|
81
56
|
end
|
82
|
-
|
83
|
-
def prepare_dir(file)
|
84
|
-
FileUtils.mkdir_p(File.dirname(file))
|
85
|
-
end
|
86
57
|
end
|
data/lib/git.rb
CHANGED
@@ -1,41 +1,45 @@
|
|
1
1
|
class Git
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
2
|
+
class << self
|
3
|
+
def clone(from,path)
|
4
|
+
system("git clone #{from} #{path}")
|
5
|
+
end
|
6
|
+
|
7
|
+
def init(path)
|
8
|
+
system("mkdir -p #{path}")
|
9
|
+
system("cd #{path} && git init")
|
10
|
+
end
|
11
|
+
|
12
|
+
def mv(orig,new)
|
13
|
+
FileUtils.mkdir_p(File.dirname(new))
|
14
|
+
system("git mv #{orig} #{new}")
|
15
|
+
self.commit("#{cleanup_name(orig)} Renamed to #{cleanup_name(new)}")
|
16
|
+
end
|
17
|
+
|
18
|
+
def add(file)
|
19
|
+
if File.exist?(file)
|
20
|
+
return system("rm #{file}") if File.zero?(file)
|
21
|
+
system("git add '#{file}'")
|
22
|
+
self.commit("#{cleanup_name(file)} Added")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def edit(file)
|
27
|
+
return rm(file) if File.zero?(file)
|
28
|
+
system("git add '#{file}'")
|
29
|
+
self.commit("#{cleanup_name(file)} Updated")
|
30
|
+
end
|
31
|
+
|
32
|
+
def rm(file)
|
33
|
+
system("git rm -f '#{file}'")
|
34
|
+
self.commit("#{cleanup_name(file)} Removed")
|
35
|
+
end
|
36
|
+
|
37
|
+
def commit(msg,*args)
|
38
|
+
system("git commit #{args.to_s} -m '#{msg}' >/dev/null")
|
39
|
+
end
|
40
|
+
|
41
|
+
def cleanup_name(f)
|
42
|
+
return f.sub(/^(.*)?\/(main|private)\/(.*)/,'\3').sub(/^@/,'')
|
43
|
+
end
|
40
44
|
end
|
41
45
|
end
|
data/lib/symbol.rb
ADDED
data/lib/yac.rb
CHANGED
@@ -1,188 +1,190 @@
|
|
1
1
|
$LOAD_PATH << File.dirname(__FILE__)
|
2
|
-
%w(git fileutils yaml format).each {|f| require f}
|
2
|
+
%w(git fileutils yaml format symbol).each {|f| require f}
|
3
3
|
|
4
|
-
module
|
4
|
+
module Yac
|
5
5
|
include Format
|
6
6
|
extend self
|
7
|
-
VERSION = '1.3.2'
|
8
|
-
YACRC = File.join("#{ENV['HOME']}",".yacrc")
|
9
7
|
|
10
|
-
|
8
|
+
VERSION = '1.4.0'
|
9
|
+
|
10
|
+
@color = {
|
11
|
+
'head1' => "1;31",
|
12
|
+
'head2' => "1;36",
|
13
|
+
'head3' => "1;33",
|
14
|
+
'head4' => "1;32",
|
15
|
+
'head5' => "1;34",
|
16
|
+
'head6' => "1;35",
|
17
|
+
'head7' => "1;37",
|
18
|
+
|
19
|
+
'shell' => "01;35",
|
20
|
+
'warn' => "31",
|
21
|
+
'notice' => "33",
|
22
|
+
'empha' => "31",
|
23
|
+
'filename' => "34",
|
24
|
+
'line_number' => "32",
|
25
|
+
}
|
11
26
|
|
12
|
-
|
27
|
+
YACRC = File.join("#{ENV['HOME']}",".yacrc")
|
28
|
+
CONFIG = YAML.load_file( File.exist?(YACRC) ? YACRC :
|
29
|
+
File.join(File.dirname(__FILE__), "..","resources","yacrc"))
|
13
30
|
|
14
31
|
CONFIG["root"] ||= File.join(ENV['HOME'],".yac")
|
15
32
|
|
16
|
-
@main_path
|
17
|
-
@
|
18
|
-
@pri_git = Git.new(@pri_path)
|
33
|
+
@main_path = File.join(CONFIG["root"],"/main/")
|
34
|
+
@pri_path = File.join(CONFIG["root"],"/private/")
|
19
35
|
|
20
36
|
def new(args)
|
21
|
-
init unless File.exist?(@main_path) && File.exist?(@pri_path)
|
22
37
|
(help && exit) if args.empty?
|
23
|
-
|
24
|
-
|
25
|
-
when "-
|
26
|
-
when "-
|
27
|
-
when "-
|
28
|
-
when "-
|
29
|
-
when "-
|
38
|
+
operate,target = args.first,args[1,args.size].join(' ')
|
39
|
+
case operate
|
40
|
+
when "-i" then init
|
41
|
+
when "-S" then search(target)
|
42
|
+
when "-u" then update(target)
|
43
|
+
when "-p" then push(target)
|
44
|
+
when "-l" then log(target)
|
45
|
+
when "-a" then add(target)
|
46
|
+
when "-e" then edit(target)
|
30
47
|
when /^(help|-h|yac|--help)$/ then help
|
31
|
-
when "-s" then shell(
|
32
|
-
when "-r" then rm(
|
48
|
+
when "-s" then shell(target)
|
49
|
+
when "-r" then rm(target)
|
33
50
|
when "-m" then mv(args[1,args.size])
|
34
51
|
when "-v" then colorful("Yac Version: #{Yac::VERSION}",'notice')
|
35
|
-
else show(
|
52
|
+
else show(operate + ' ' + target)
|
36
53
|
end
|
37
54
|
end
|
38
55
|
|
39
56
|
def init
|
40
|
-
FileUtils.mkdir_p(CONFIG['root'])
|
41
57
|
{"main" => @main_path,"private" => @pri_path}.each do |name,path|
|
42
58
|
if File.exist?(path)
|
43
59
|
colorful("#{name} repository has already initialized.","notice")
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
Git.clone(CONFIG["#{name}"]['clone-from'],CONFIG['root'],name)
|
48
|
-
else
|
49
|
-
colorful("Initialize #{name} repository from scratch to #{CONFIG['root']}/#{name}","notice")
|
50
|
-
prepare_dir(path)
|
51
|
-
Git.init(path)
|
52
|
-
end
|
60
|
+
elsif CONFIG["#{name}"] && CONFIG["#{name}"]['clone-from']
|
61
|
+
colorful("Initialize #{name} repository from #{CONFIG[name]['clone-from']}","notice")
|
62
|
+
Git.clone(CONFIG["#{name}"]['clone-from'],path)
|
53
63
|
end
|
54
64
|
end
|
55
65
|
end
|
56
66
|
|
57
67
|
def show(args)
|
58
|
-
|
68
|
+
loop do
|
69
|
+
file = search_name(args,"Show")
|
70
|
+
file ? handle_file(file) : break
|
71
|
+
end
|
59
72
|
end
|
60
73
|
|
61
74
|
def search(args)
|
62
|
-
|
63
|
-
end
|
64
|
-
|
65
|
-
def update(args)
|
66
|
-
git_command(args,'pull')
|
67
|
-
rescue
|
68
|
-
colorful("ERROR: can not update the repository,\n\n#{$!}","warn")
|
69
|
-
end
|
70
|
-
|
71
|
-
def push(args)
|
72
|
-
git_command(args,'push')
|
73
|
-
rescue
|
74
|
-
colorful("Usage:\nyac push ( main | all )\n\nTry `yac -h` for more help\n\n#{$1}","warn")
|
75
|
-
end
|
76
|
-
|
77
|
-
def log(args)
|
78
|
-
git_command(args,'log --color --date-order --reverse')
|
75
|
+
search_content(args)
|
79
76
|
end
|
80
77
|
|
81
|
-
def
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
end
|
87
|
-
|
88
|
-
git_path.each do |x|
|
89
|
-
colorful(x,'filename')
|
90
|
-
colorful( `cd #{x} && git #{command}` ,"notice")
|
78
|
+
def add(args)
|
79
|
+
file = add_file(args,'.yac')
|
80
|
+
if file && confirm("You Are Adding #{file}")
|
81
|
+
edit_text(file)
|
82
|
+
Git.add(file)
|
91
83
|
end
|
92
84
|
end
|
93
85
|
|
94
86
|
def edit(args)
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
87
|
+
file = search_name(args,"Edit")
|
88
|
+
if file
|
89
|
+
handle_file(file,'edit')
|
90
|
+
Git.edit(file)
|
91
|
+
end
|
100
92
|
end
|
101
93
|
|
102
94
|
def rm(args)
|
103
|
-
|
95
|
+
file = search_name(args,"Remove")
|
96
|
+
if file && confirm("You Are Removing #{file}.")
|
97
|
+
Git.rm(file)
|
98
|
+
end
|
104
99
|
end
|
105
100
|
|
106
101
|
def help
|
107
|
-
|
102
|
+
handle_file(File.dirname(__FILE__)+"/../README.rdoc")
|
108
103
|
end
|
109
104
|
|
110
105
|
def shell(args)
|
111
|
-
|
112
|
-
when /main/
|
106
|
+
if args.to_s =~ /main/
|
113
107
|
colorful(" Welcome To The Main Yac Repository","notice")
|
114
|
-
system
|
108
|
+
system("cd '#{@main_path}'; sh")
|
115
109
|
else
|
116
110
|
colorful(" Welcome To The Private Yac Repository","notice")
|
117
|
-
system
|
111
|
+
system("cd '#{@pri_path}'; sh")
|
118
112
|
end
|
119
113
|
end
|
120
114
|
|
121
115
|
def mv(args)
|
122
|
-
(colorful("Usage:\nyac mv [orign_name] [new_name]
|
116
|
+
(colorful("Usage:\nyac mv [orign_name] [new_name]","warn");exit) unless args.size == 2
|
123
117
|
file = search_name(args[0],"Rename")
|
124
|
-
|
125
|
-
|
126
|
-
|
118
|
+
|
119
|
+
# You can use $ yac mv linux linux/ to rename linux to linux/linux
|
120
|
+
new_filename = args[1] =~ /\/$/ ? args[1] : args[1] + file.match(/[^\/]$/).to_s
|
121
|
+
new_filename = '@' + new_filename if file =~ /^#{@main_path}/
|
122
|
+
new_name = add_file(new_filename)
|
123
|
+
|
127
124
|
if new_name && confirm("You Are Renaming #{file} To #{new_name}")
|
128
|
-
|
129
|
-
@working_git.mv(file,new_name)
|
125
|
+
Git.mv(file,new_name)
|
130
126
|
end
|
131
127
|
end
|
132
128
|
|
133
129
|
protected
|
134
|
-
def
|
135
|
-
|
136
|
-
if
|
137
|
-
edit_text(file)
|
138
|
-
@working_git.add(file)
|
139
|
-
end
|
140
|
-
end
|
141
|
-
|
142
|
-
def add_file(args,suffix = ".ch")
|
143
|
-
if args.include?('/') && args =~ /(@?)(?:(.*)\/)(.+)/ #choose directory
|
130
|
+
def add_file(args,*suffix)
|
131
|
+
suffix = suffix ? suffix.to_s : ''
|
132
|
+
if args.include?('/') && args =~ /(@?)(?:(.*)\/)(.+)/ #choose directory
|
144
133
|
prefix,path_name,file_name = $1,$2,$3
|
145
|
-
path = prefix.empty? ? @pri_path : @main_path
|
146
|
-
#
|
134
|
+
path = prefix.empty? ? @pri_path : @main_path #choose git path
|
135
|
+
# Use 'l/e' to choose 'linux/gentoo'
|
147
136
|
all_path = %x{
|
148
|
-
find #{path} -type d -iwholename '#{path}*#{path_name.gsub(/\//,'*/*')}*' -not -iwholename '
|
137
|
+
find -L #{path} -type d -iwholename '#{path}*#{path_name.gsub(/\//,'*/*')}*' -not -iwholename '*\/.git\/*' | sed 's/^.*\\/\\(private\\|main\\)\\//#{prefix}/'
|
149
138
|
}.to_a.map(&:strip).concat([prefix+path_name]).uniq
|
150
139
|
|
151
140
|
colorful("Which directory do you want to use:","notice")
|
152
141
|
choosed_path = choose_one(all_path)
|
153
|
-
return full_path(choosed_path + "/" + file_name + suffix)
|
142
|
+
return choosed_path ? full_path(choosed_path + "/" + file_name + suffix) : false
|
154
143
|
else
|
155
|
-
return full_path(args+suffix)
|
144
|
+
return full_path(args + suffix)
|
156
145
|
end
|
157
146
|
end
|
158
147
|
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
148
|
+
#
|
149
|
+
# Git
|
150
|
+
#
|
151
|
+
|
152
|
+
def update(args)
|
153
|
+
git_command(args,'pull')
|
164
154
|
end
|
165
155
|
|
166
|
-
def
|
167
|
-
|
168
|
-
if file && confirm("You Are Removing #{file}.")
|
169
|
-
@working_git.rm(file)
|
170
|
-
end
|
156
|
+
def push(args)
|
157
|
+
git_command(args,'push')
|
171
158
|
end
|
172
159
|
|
173
|
-
def
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
160
|
+
def log(args)
|
161
|
+
git_command(args,'log --color')
|
162
|
+
end
|
163
|
+
|
164
|
+
def git_command(env,command)
|
165
|
+
case env.to_s
|
166
|
+
when /main/ then git_path = [@main_path]
|
167
|
+
when /all/ then git_path = [@main_path,@pri_path]
|
168
|
+
else git_path = [@pri_path]
|
169
|
+
end
|
170
|
+
|
171
|
+
git_path.each do |x|
|
172
|
+
colorful(x,'filename')
|
173
|
+
system("cd #{x} && git #{command}")
|
178
174
|
end
|
179
175
|
end
|
180
176
|
|
181
|
-
|
182
|
-
|
177
|
+
#
|
178
|
+
# Search
|
179
|
+
#
|
180
|
+
|
181
|
+
def search_name(args,msg)
|
182
|
+
path = (args =~ /^(@)/) ? [@pri_path] : [@main_path , @pri_path]
|
183
183
|
result = []
|
184
184
|
path.each do |x|
|
185
|
-
result.concat(
|
185
|
+
result.concat( %x{
|
186
|
+
find -L "#{x}" -type f -iwholename '#{x}*#{args.gsub(/\//,'*/*').sub(/^@/,'').strip}*' -not -iwholename '*\/.git\/*'| sed 's/^.*\\/\\(private\\|main\\)\\//#{x=~/main/ ? '@':'' }/'
|
187
|
+
}.to_a )
|
186
188
|
end
|
187
189
|
|
188
190
|
if result.empty?
|
@@ -195,58 +197,65 @@ module Yac
|
|
195
197
|
end
|
196
198
|
|
197
199
|
def search_content(args)
|
198
|
-
|
199
|
-
|
200
|
+
# find -type f -exec sh -c 'file="{}";type=$(file $file);[[ $type =~ " text" ]] && echo $file' \; => Too slow
|
201
|
+
|
202
|
+
# If use @ as prefix , only search private repository
|
203
|
+
result = args.sub!(/^@/,'') ? [] : %x(
|
204
|
+
find "#{@main_path}" -not -iwholename '*\/.git\/*' | grep -E '*\.[ch|yac|yml]'| xargs grep -HniP '#{args}' | sed 's/^/@/g'
|
205
|
+
).to_a
|
206
|
+
|
207
|
+
result.concat %x(
|
208
|
+
find "#{@pri_path}" -not -iwholename '*\/.git\/*' | grep -E '*\.[ch|yac|yml]'| xargs grep -HniP '#{args}'
|
209
|
+
).to_a
|
210
|
+
|
200
211
|
all_result = []
|
201
212
|
result.each do |x|
|
202
213
|
stuff = x.split(':',3)
|
203
214
|
colorful(File.basename(stuff[0]).sub(/\..*/,''),"filename",false)
|
204
215
|
colorful(stuff[1],"line_number",false)
|
205
|
-
|
216
|
+
format_text(stuff[2],/((#{args}))/i)
|
206
217
|
all_result << stuff[0].sub(/(@?).*\/(?:main|private)\/(.*)/,'\1'+'\2')
|
207
218
|
end
|
208
219
|
all_result.uniq!
|
209
220
|
loop do
|
210
|
-
colorful("All files Contain #{args.strip}
|
221
|
+
colorful("All files Contain #{args.strip}","notice")
|
211
222
|
file = full_path(choose_one(all_result))
|
212
|
-
file ?
|
223
|
+
file ? handle_file(file) : break
|
213
224
|
end
|
214
225
|
end
|
215
226
|
|
216
|
-
def full_path(
|
217
|
-
return false unless
|
218
|
-
|
219
|
-
|
220
|
-
file = @main_path + args.sub(/^@/,"")
|
221
|
-
else
|
222
|
-
@working_git = @pri_git
|
223
|
-
file = @pri_path + args
|
224
|
-
end
|
225
|
-
return file.strip
|
227
|
+
def full_path(filename)
|
228
|
+
return false unless filename
|
229
|
+
filename.sub!(/^@/,'') ? Dir.chdir(@main_path) : Dir.chdir(@pri_path)
|
230
|
+
return filename.strip
|
226
231
|
end
|
227
232
|
|
228
233
|
def confirm(*msg)
|
229
|
-
colorful("#{msg.to_s}\nAre You Sure (Y/N) (q
|
234
|
+
colorful("#{msg.to_s}\nAre You Sure (Y/N) (q:quit):","notice",false)
|
230
235
|
return STDIN.gets.to_s =~ /n|q/i ? false : true
|
231
236
|
end
|
232
237
|
|
233
|
-
def choose_one(
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
printf "\n"
|
241
|
-
num = choose_range(stuff.size)
|
242
|
-
return stuff[num-1].to_s.strip #return the filename
|
238
|
+
def choose_one(args)
|
239
|
+
return false unless args.size > 0
|
240
|
+
|
241
|
+
args.each_index do |x|
|
242
|
+
printf "\e[%dm%3s\e[0m" % [args[x] =~ /^@/ ? 36:34,x+1]
|
243
|
+
printf " %-22s" % [trancate_filename(args[x].strip)]
|
244
|
+
print "\n" if (x+1)%3 == 0
|
243
245
|
end
|
244
|
-
|
246
|
+
puts "\n" if args.size%3 != 0
|
247
|
+
|
248
|
+
num = choose_range(args.size)
|
249
|
+
return num ? args[num-1].to_s.strip : false #return the filename
|
250
|
+
end
|
251
|
+
|
252
|
+
def trancate_filename(name)
|
253
|
+
name.sub!(/\..*$/,'').sub!(/^@/,'')
|
254
|
+
content = name.size > 22 ? '..' + name.reverse[0,20].reverse : name
|
245
255
|
end
|
246
256
|
|
247
|
-
#choose a valid number
|
248
257
|
def choose_range(size)
|
249
|
-
colorful("Please Input A Valid Number
|
258
|
+
colorful("Please Input A Valid Number (1..#{size}) (q:quit): ","notice",false)
|
250
259
|
num = STDIN.gets
|
251
260
|
return false if num =~ /q/i
|
252
261
|
choosed_num = num.strip.empty? ? 1 : num.to_i
|
data/resources/yacrc
CHANGED
@@ -1,54 +1,19 @@
|
|
1
1
|
#root:
|
2
|
-
|
2
|
+
|
3
3
|
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
|
-
pdf_command: evince
|
11
|
-
office_command: ooffice
|
12
|
-
#image_command: evince
|
13
|
-
#editor: vim
|
14
|
-
#pdf_edit_command: ooffice
|
15
|
-
#image_edit_command: gimp
|
16
10
|
|
17
|
-
|
18
|
-
head2: "1;36"
|
19
|
-
head3: "1;33"
|
20
|
-
head4: "1;32"
|
21
|
-
head5: "1;34"
|
22
|
-
head6: "1;35"
|
23
|
-
head7: "1;37"
|
11
|
+
editor: vim
|
24
12
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
filename: "34"
|
29
|
-
line_number: "32"
|
30
|
-
text:
|
13
|
+
show_pdf: evince
|
14
|
+
show_image: eog
|
15
|
+
show_office: ooffice
|
31
16
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
#5 - " " " Blink
|
36
|
-
#8 - " " " Hidden (same color as bg)
|
37
|
-
#30 - " " " Black
|
38
|
-
#31 - " " " Red
|
39
|
-
#32 - " " " Green
|
40
|
-
#33 - " " " Yellow
|
41
|
-
#34 - " " " Blue
|
42
|
-
#35 - " " " Magenta
|
43
|
-
#36 - " " " Cyan
|
44
|
-
#37 - " " " White
|
45
|
-
#40 - Change background to Black
|
46
|
-
#41 - " " " Red
|
47
|
-
#42 - " " " Green
|
48
|
-
#43 - " " " Yellow
|
49
|
-
#44 - " " " Blue
|
50
|
-
#45 - " " " Magenta
|
51
|
-
#46 - " " " Cyan
|
52
|
-
#47 - " " " White
|
53
|
-
#0 - Turn off all attributes.
|
54
|
-
#7 - Change to Black text on a White background
|
17
|
+
edit_pdf: ooffice
|
18
|
+
edit_image: gimp
|
19
|
+
edit_office: ooffice
|
data/yac.gemspec
CHANGED
@@ -2,17 +2,17 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{yac}
|
5
|
-
s.version = "1.
|
5
|
+
s.version = "1.4.0"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Jinzhu Zhang"]
|
9
|
-
s.date = %q{2008-12-
|
9
|
+
s.date = %q{2008-12-28}
|
10
10
|
s.default_executable = %q{yac}
|
11
11
|
s.description = %q{Yet Another Cheat: sexy command line tool for cheat sheet.}
|
12
12
|
s.email = %q{wosmvp@gmail.com}
|
13
13
|
s.executables = ["yac"]
|
14
|
-
s.extra_rdoc_files = ["CHANGELOG", "bin/yac", "lib/git.rb", "lib/format.rb", "lib/yac.rb", "README.rdoc"]
|
15
|
-
s.files = ["CHANGELOG", "resources/yacrc", "bin/yac", "Rakefile", "
|
14
|
+
s.extra_rdoc_files = ["CHANGELOG", "bin/yac", "lib/git.rb", "lib/format.rb", "lib/symbol.rb", "lib/yac.rb", "README.rdoc"]
|
15
|
+
s.files = ["Manifest", "CHANGELOG", "resources/yacrc", "bin/yac", "Rakefile", "lib/git.rb", "lib/format.rb", "lib/symbol.rb", "lib/yac.rb", "README.rdoc", "yac.gemspec"]
|
16
16
|
s.has_rdoc = true
|
17
17
|
s.homepage = %q{http://www.zhangjinzhu.com}
|
18
18
|
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Yac", "--main", "README.rdoc"]
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yac
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jinzhu Zhang
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-12-
|
12
|
+
date: 2008-12-28 00:00:00 +08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -24,19 +24,21 @@ extra_rdoc_files:
|
|
24
24
|
- bin/yac
|
25
25
|
- lib/git.rb
|
26
26
|
- lib/format.rb
|
27
|
+
- lib/symbol.rb
|
27
28
|
- lib/yac.rb
|
28
29
|
- README.rdoc
|
29
30
|
files:
|
31
|
+
- Manifest
|
30
32
|
- CHANGELOG
|
31
33
|
- resources/yacrc
|
32
34
|
- bin/yac
|
33
35
|
- Rakefile
|
34
|
-
- yac.gemspec
|
35
36
|
- lib/git.rb
|
36
37
|
- lib/format.rb
|
38
|
+
- lib/symbol.rb
|
37
39
|
- lib/yac.rb
|
38
40
|
- README.rdoc
|
39
|
-
-
|
41
|
+
- yac.gemspec
|
40
42
|
has_rdoc: true
|
41
43
|
homepage: http://www.zhangjinzhu.com
|
42
44
|
post_install_message:
|