my_help 0.3.2 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +87 -32
- data/README_en.md +31 -4
- data/Rakefile +10 -0
- data/exe/e_h +4 -0
- data/exe/t_h +4 -0
- data/exe/template_help +4 -0
- data/hikis/README_en.hiki +31 -4
- data/hikis/README_ja.hiki +85 -32
- data/lib/daddygongon/template_help +15 -11
- data/lib/emacs_help.rb +122 -0
- data/lib/my_help/#test.rb# +26 -0
- data/lib/my_help/.#test.rb +1 -0
- data/lib/my_help/test.rb +26 -0
- data/lib/my_help/version.rb +1 -1
- data/lib/my_help.rb +46 -22
- data/lib/my_help.rb~ +155 -0
- data/lib/specific_help.rb +72 -15
- data/my_help.wiki/Home.md +87 -32
- data/my_help.wiki/README_en.md +31 -4
- data/my_help.wiki/README_ja.md +87 -32
- metadata +13 -2
@@ -0,0 +1,26 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'yaml'
|
3
|
+
require 'pp'
|
4
|
+
yaml =<<EOF
|
5
|
+
:file:
|
6
|
+
:opts:
|
7
|
+
:short: "-f"
|
8
|
+
:long: "--��Ւ��������"
|
9
|
+
:desc: File������
|
10
|
+
:title: ��Ւ�������������file
|
11
|
+
:cont:
|
12
|
+
- c-x c-f, Find file, ��Ւ�������뒤���
|
13
|
+
- c-x c-s, Save file, ��Ւ�������뒤��ݒ¸
|
14
|
+
- c-x c-w, Write file NAME, ��Ւ�������뒤��̒̾��ǒ�������
|
15
|
+
EOF
|
16
|
+
pp data=YAML.load(yaml)
|
17
|
+
print YAML.dump(data)
|
18
|
+
|
19
|
+
|
20
|
+
data0={:new_item=>
|
21
|
+
{:opts=>{:short=>"-n", :long=>"--new_item", :desc=>"new item"},
|
22
|
+
:title=>"new_item",
|
23
|
+
:cont=>
|
24
|
+
["new cont"]}}
|
25
|
+
|
26
|
+
print YAML.dump(data0)
|
@@ -0,0 +1 @@
|
|
1
|
+
bob@bob.local.71520
|
data/lib/my_help/test.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'yaml'
|
3
|
+
require 'pp'
|
4
|
+
yaml =<<EOF
|
5
|
+
:file:
|
6
|
+
:opts:
|
7
|
+
:short: "-f"
|
8
|
+
:long: "--ファイル"
|
9
|
+
:desc: File操作
|
10
|
+
:title: ファイル操作file
|
11
|
+
:cont:
|
12
|
+
- c-x c-f, Find file, ファイルを開く
|
13
|
+
- c-x c-s, Save file, ファイルを保存
|
14
|
+
- c-x c-w, Write file NAME, ファイルを別名で書き込む
|
15
|
+
EOF
|
16
|
+
pp data=YAML.load(yaml)
|
17
|
+
print YAML.dump(data)
|
18
|
+
|
19
|
+
|
20
|
+
data0={:new_item=>
|
21
|
+
{:opts=>{:short=>"-n", :long=>"--new_item", :desc=>"new item"},
|
22
|
+
:title=>"new_item",
|
23
|
+
:cont=>
|
24
|
+
["new cont"]}}
|
25
|
+
|
26
|
+
print YAML.dump(data0)
|
data/lib/my_help/version.rb
CHANGED
data/lib/my_help.rb
CHANGED
@@ -16,18 +16,18 @@ module MyHelp
|
|
16
16
|
|
17
17
|
def initialize(argv=[])
|
18
18
|
@argv = argv
|
19
|
-
@
|
20
|
-
@
|
19
|
+
@default_help_dir = File.expand_path("../../lib/daddygongon", __FILE__)
|
20
|
+
@local_help_dir = File.join(ENV['HOME'],'.my_help')
|
21
21
|
set_help_dir_if_not_exists
|
22
22
|
end
|
23
23
|
|
24
24
|
def set_help_dir_if_not_exists
|
25
|
-
return if File::exists?(@
|
26
|
-
FileUtils.mkdir_p(@
|
27
|
-
Dir.entries(@
|
28
|
-
file_path=File.join(@
|
25
|
+
return if File::exists?(@local_help_dir)
|
26
|
+
FileUtils.mkdir_p(@local_help_dir, :verbose=>true)
|
27
|
+
Dir.entries(@default_help_dir).each{|file|
|
28
|
+
file_path=File.join(@local_help_dir,file)
|
29
29
|
next if File::exists?(file_path)
|
30
|
-
FileUtils.cp((File.join(@
|
30
|
+
FileUtils.cp((File.join(@default_help_dir,file)),@local_help_dir,:verbose=>true)
|
31
31
|
}
|
32
32
|
end
|
33
33
|
|
@@ -44,6 +44,7 @@ module MyHelp
|
|
44
44
|
opt.on('-m', '--make', 'make executables for all helps.'){make_help}
|
45
45
|
opt.on('-c', '--clean', 'clean up exe dir.'){clean_exe}
|
46
46
|
opt.on('--install_local','install local after edit helps'){install_local}
|
47
|
+
opt.on('--delete NAME','delete NAME help'){|file| delete_help(file)}
|
47
48
|
end
|
48
49
|
begin
|
49
50
|
command_parser.parse!(@argv)
|
@@ -53,13 +54,29 @@ module MyHelp
|
|
53
54
|
exit
|
54
55
|
end
|
55
56
|
|
57
|
+
def delete_help(file)
|
58
|
+
del_files=[]
|
59
|
+
del_files << File.join(@local_help_dir,file)
|
60
|
+
exe_dir=File.join(File.expand_path('../..',@default_help_dir),'exe')
|
61
|
+
del_files << File.join(exe_dir,file)
|
62
|
+
p del_files << File.join(exe_dir,short_name(file))
|
63
|
+
print "Are you sure to delete these files?[yes]"
|
64
|
+
if gets.chomp=='yes' then
|
65
|
+
del_files.each{|file| FileUtils.rm(file,:verbose=>true)}
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
USER_INST_DIR="USER INSTALLATION DIRECTORY:"
|
70
|
+
INST_DIR="INSTALLATION DIRECTORY:"
|
56
71
|
def install_local
|
57
|
-
Dir.chdir(File.expand_path('../..',@
|
72
|
+
Dir.chdir(File.expand_path('../..',@default_help_dir))
|
58
73
|
p pwd_dir = Dir.pwd
|
59
74
|
# check that the working dir should not the gem installed dir,
|
60
75
|
# which destroys itself.
|
61
|
-
|
62
|
-
|
76
|
+
status, stdout, stderr = systemu "gem env|grep '#{USER_INST_DIR}'"
|
77
|
+
if stdout==""
|
78
|
+
status, stdout, stderr = systemu "gem env|grep '#{INST_DIR}'"
|
79
|
+
end
|
63
80
|
p system_inst_dir = stdout.split(': ')[1].chomp
|
64
81
|
if pwd_dir == system_inst_dir
|
65
82
|
puts "Download my_help from github, and using bundle for edit helps\n"
|
@@ -77,8 +94,7 @@ module MyHelp
|
|
77
94
|
end
|
78
95
|
|
79
96
|
def make_help
|
80
|
-
|
81
|
-
next if file[0]=='#' or file[-1]=='~'
|
97
|
+
local_help_entries.each{|file|
|
82
98
|
exe_cont="#!/usr/bin/env ruby\nrequire 'specific_help'\n"
|
83
99
|
exe_cont << "help_file = File.join(ENV['HOME'],'.my_help','#{file}')\n"
|
84
100
|
exe_cont << "SpecificHelp::Command.run(help_file, ARGV)\n"
|
@@ -92,8 +108,7 @@ module MyHelp
|
|
92
108
|
end
|
93
109
|
|
94
110
|
def clean_exe
|
95
|
-
|
96
|
-
next if file[0]=='#' or file[-1]=='~'
|
111
|
+
local_help_entries.each{|file|
|
97
112
|
next if file.include?('emacs_help') or file.include?('e_h')
|
98
113
|
next if file.include?('template_help') or file.include?('t_h')
|
99
114
|
[file, short_name(file)].each{|name|
|
@@ -104,27 +119,36 @@ module MyHelp
|
|
104
119
|
end
|
105
120
|
|
106
121
|
def init_help(file)
|
107
|
-
p target_help=File.join(@
|
122
|
+
p target_help=File.join(@local_help_dir,file)
|
108
123
|
if File::exists?(target_help)
|
109
124
|
puts "File exists. rm it first to initialize it."
|
110
125
|
exit
|
111
126
|
end
|
112
|
-
p template = File.join(@
|
127
|
+
p template = File.join(@default_help_dir,'template_help')
|
113
128
|
FileUtils::Verbose.cp(template,target_help)
|
114
129
|
end
|
115
130
|
|
116
131
|
def edit_help(file)
|
117
|
-
p target_help=File.join(@
|
132
|
+
p target_help=File.join(@local_help_dir,file)
|
118
133
|
system "emacs #{target_help}"
|
119
134
|
end
|
120
135
|
|
136
|
+
def local_help_entries
|
137
|
+
entries= []
|
138
|
+
Dir.entries(@local_help_dir).each{|file|
|
139
|
+
next unless file.include?('_')
|
140
|
+
next if file[0]=='#' or file[-1]=='~' or file[0]=='.'
|
141
|
+
entries << file
|
142
|
+
}
|
143
|
+
return entries
|
144
|
+
end
|
145
|
+
|
121
146
|
def list_helps
|
122
147
|
print "Specific help file:\n"
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
print " #{file}\t:#{help_cont[:head][0][0..-1]}\n"
|
148
|
+
local_help_entries.each{|file|
|
149
|
+
file_path=File.join(@local_help_dir,file)
|
150
|
+
help = YAML.load(File.read(file_path))
|
151
|
+
print " #{file}\t:#{help[:head][0]}\n"
|
128
152
|
}
|
129
153
|
end
|
130
154
|
end
|
data/lib/my_help.rb~
ADDED
@@ -0,0 +1,155 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require "optparse"
|
3
|
+
require "yaml"
|
4
|
+
require "fileutils"
|
5
|
+
#require "emacs_help/version"
|
6
|
+
require "my_help/version"
|
7
|
+
require "systemu"
|
8
|
+
#require "emacs_help"
|
9
|
+
|
10
|
+
module MyHelp
|
11
|
+
class Command
|
12
|
+
|
13
|
+
def self.run(argv=[])
|
14
|
+
new(argv).execute
|
15
|
+
end
|
16
|
+
|
17
|
+
def initialize(argv=[])
|
18
|
+
@argv = argv
|
19
|
+
@default_help_dir = File.expand_path("../../lib/daddygongon", __FILE__)
|
20
|
+
@local_help_dir = File.join(ENV['HOME'],'.my_help')
|
21
|
+
set_help_dir_if_not_exists
|
22
|
+
end
|
23
|
+
|
24
|
+
def set_help_dir_if_not_exists
|
25
|
+
return if File::exists?(@local_help_dir)
|
26
|
+
FileUtils.mkdir_p(@local_help_dir, :verbose=>true)
|
27
|
+
Dir.entries(@default_help_dir).each{|file|
|
28
|
+
file_path=File.join(@local_help_dir,file)
|
29
|
+
next if File::exists?(file_path)
|
30
|
+
FileUtils.cp((File.join(@default_help_dir,file)),@local_help_dir,:verbose=>true)
|
31
|
+
}
|
32
|
+
end
|
33
|
+
|
34
|
+
def execute
|
35
|
+
@argv << '--help' if @argv.size==0
|
36
|
+
command_parser = OptionParser.new do |opt|
|
37
|
+
opt.on('-v', '--version','show program Version.') { |v|
|
38
|
+
opt.version = MyHelp::VERSION
|
39
|
+
puts opt.ver
|
40
|
+
}
|
41
|
+
opt.on('-l', '--list', 'list specific helps'){list_helps}
|
42
|
+
opt.on('-e NAME', '--edit NAME', 'edit NAME help(eg test_help)'){|file| edit_help(file)}
|
43
|
+
opt.on('-i NAME', '--init NAME', 'initialize NAME help(eg test_help).'){|file| init_help(file)}
|
44
|
+
opt.on('-m', '--make', 'make executables for all helps.'){make_help}
|
45
|
+
opt.on('-c', '--clean', 'clean up exe dir.'){clean_exe}
|
46
|
+
opt.on('--install_local','install local after edit helps'){install_local}
|
47
|
+
opt.on('--delete NAME','delete NAME help'){|file| delete_help(file)}
|
48
|
+
end
|
49
|
+
begin
|
50
|
+
command_parser.parse!(@argv)
|
51
|
+
rescue=> eval
|
52
|
+
p eval
|
53
|
+
end
|
54
|
+
exit
|
55
|
+
end
|
56
|
+
|
57
|
+
def delete_help(file)
|
58
|
+
del_files=[]
|
59
|
+
del_files << File.join(@local_help_dir,file)
|
60
|
+
exe_dir=File.join(File.expand_path('../..',@default_help_dir),'exe')
|
61
|
+
del_files << File.join(exe_dir,file)
|
62
|
+
p del_files << File.join(exe_dir,short_name(file))
|
63
|
+
print "Are you sure to delete these files?[yes]"
|
64
|
+
if gets.chomp=='yes' then
|
65
|
+
del_files.each{|file| FileUtils.rm(file,:verbose=>true)}
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
USER_INST_DIR="USER INSTALLATION DIRECTORY:"
|
70
|
+
INST_DIR="INSTALLATION DIRECTORY:"
|
71
|
+
def install_local
|
72
|
+
Dir.chdir(File.expand_path('../..',@default_help_dir))
|
73
|
+
p pwd_dir = Dir.pwd
|
74
|
+
# check that the working dir should not the gem installed dir,
|
75
|
+
# which destroys itself.
|
76
|
+
status, stdout, stderr = systemu "gem env|grep '#{USER_INST_DIR}'"
|
77
|
+
if stdout==""
|
78
|
+
status, stdout, stderr = systemu "gem env|grep '#{INST_DIR}'"
|
79
|
+
end
|
80
|
+
p system_inst_dir = stdout.split(': ')[1].chomp
|
81
|
+
if pwd_dir == system_inst_dir
|
82
|
+
puts "Download my_help from github, and using bundle for edit helps\n"
|
83
|
+
puts "Read README in detail.\n"
|
84
|
+
exit
|
85
|
+
end
|
86
|
+
system "git add -A"
|
87
|
+
system "git commit -m 'update exe dirs'"
|
88
|
+
system "Rake install:local"
|
89
|
+
end
|
90
|
+
|
91
|
+
def short_name(file)
|
92
|
+
file_name=file.split('_')
|
93
|
+
return file_name[0][0]+"_"+file_name[1][0]
|
94
|
+
end
|
95
|
+
|
96
|
+
def make_help
|
97
|
+
local_help_entries.each{|file|
|
98
|
+
exe_cont="#!/usr/bin/env ruby\nrequire 'specific_help'\n"
|
99
|
+
exe_cont << "help_file = File.join(ENV['HOME'],'.my_help','#{file}')\n"
|
100
|
+
exe_cont << "SpecificHelp::Command.run(help_file, ARGV)\n"
|
101
|
+
[file, short_name(file)].each{|name|
|
102
|
+
p target=File.join('exe',name)
|
103
|
+
File.open(target,'w'){|file| file.print exe_cont}
|
104
|
+
FileUtils.chmod('a+x', target, :verbose => true)
|
105
|
+
}
|
106
|
+
}
|
107
|
+
install_local
|
108
|
+
end
|
109
|
+
|
110
|
+
def clean_exe
|
111
|
+
local_help_entries.each{|file|
|
112
|
+
next if file.include?('emacs_help') or file.include?('e_h')
|
113
|
+
next if file.include?('template_help') or file.include?('t_h')
|
114
|
+
[file, short_name(file)].each{|name|
|
115
|
+
p target=File.join('exe',name)
|
116
|
+
FileUtils::Verbose.rm(target)
|
117
|
+
}
|
118
|
+
}
|
119
|
+
end
|
120
|
+
|
121
|
+
def init_help(file)
|
122
|
+
p target_help=File.join(@local_help_dir,file)
|
123
|
+
if File::exists?(target_help)
|
124
|
+
puts "File exists. rm it first to initialize it."
|
125
|
+
exit
|
126
|
+
end
|
127
|
+
p template = File.join(@default_help_dir,'template_help')
|
128
|
+
FileUtils::Verbose.cp(template,target_help)
|
129
|
+
end
|
130
|
+
|
131
|
+
def edit_help(file)
|
132
|
+
p target_help=File.join(@local_help_dir,file)
|
133
|
+
system "emacs #{target_help}"
|
134
|
+
end
|
135
|
+
|
136
|
+
def local_help_entries
|
137
|
+
entries= []
|
138
|
+
Dir.entries(@local_help_dir).each{|file|
|
139
|
+
next unless file.include?('_')
|
140
|
+
next if file[0]=='#' or file[-1]=='~'
|
141
|
+
entries << file
|
142
|
+
}
|
143
|
+
return entries
|
144
|
+
end
|
145
|
+
|
146
|
+
def list_helps
|
147
|
+
print "Specific help file:\n"
|
148
|
+
local_help_entries.each{|file|
|
149
|
+
file_path=File.join(@local_help_dir,file)
|
150
|
+
help = YAML.load(File.read(file_path))
|
151
|
+
print " #{file}\t:#{help[:head][0]}\n"
|
152
|
+
}
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
data/lib/specific_help.rb
CHANGED
@@ -3,7 +3,6 @@ require "optparse"
|
|
3
3
|
require "yaml"
|
4
4
|
require "my_help/version"
|
5
5
|
|
6
|
-
|
7
6
|
module SpecificHelp
|
8
7
|
class Command
|
9
8
|
|
@@ -15,13 +14,18 @@ module SpecificHelp
|
|
15
14
|
@source_file = file
|
16
15
|
@help_cont = YAML.load(File.read(file))
|
17
16
|
@help_cont[:head].each{|line| print line.chomp+"\n" }
|
18
|
-
@help_cont[:license].each{|line| print line } if @help_cont[:license] != nil
|
19
|
-
print "---\n" #separater
|
17
|
+
@help_cont[:license].each{|line| print "#{line.chomp}\n" } if @help_cont[:license] != nil
|
20
18
|
@argv = argv
|
21
19
|
end
|
22
20
|
|
23
21
|
def execute
|
24
|
-
|
22
|
+
if @argv.size==0
|
23
|
+
if @source_file.include?('todo')
|
24
|
+
@argv << '--all'
|
25
|
+
else
|
26
|
+
@argv << '--help'
|
27
|
+
end
|
28
|
+
end
|
25
29
|
command_parser = OptionParser.new do |opt|
|
26
30
|
opt.on('-v', '--version','show program Version.') { |v|
|
27
31
|
opt.version = MyHelp::VERSION
|
@@ -30,10 +34,14 @@ module SpecificHelp
|
|
30
34
|
@help_cont.each_pair{|key,val|
|
31
35
|
next if key==:head or key==:license
|
32
36
|
opts = val[:opts]
|
33
|
-
opt.on(opts[:short],opts[:long],opts[:desc]) {
|
37
|
+
opt.on(opts[:short],opts[:long],opts[:desc]) {disp_help(key)}
|
34
38
|
}
|
35
39
|
opt.on('--edit','edit help contents'){edit_help}
|
36
40
|
opt.on('--to_hiki','convert to hikidoc format'){to_hiki}
|
41
|
+
opt.on('--all','display all helps'){all_help}
|
42
|
+
opt.on('--store [item]','store [item] in backfile'){|item| store(item)}
|
43
|
+
opt.on('--remove [item]','remove [item] and store in backfile'){|item| remove(item) }
|
44
|
+
opt.on('--add [item]','add new [item]'){|item| add(item) }
|
37
45
|
end
|
38
46
|
# begin
|
39
47
|
command_parser.parse!(@argv)
|
@@ -43,34 +51,83 @@ module SpecificHelp
|
|
43
51
|
exit
|
44
52
|
end
|
45
53
|
|
54
|
+
def mk_backup_file(file)
|
55
|
+
path = File.dirname(file)
|
56
|
+
base = File.basename(file)
|
57
|
+
backup= File.join(path,"."+base)
|
58
|
+
FileUtils.touch(backup) unless File.exists?(backup)
|
59
|
+
return backup
|
60
|
+
end
|
61
|
+
|
62
|
+
def store(item)
|
63
|
+
backup=mk_backup_file(@source_file)
|
64
|
+
store_item = @help_cont[item.to_sym]
|
65
|
+
p store_name = item+"_"+Time.now.strftime("%Y%m%d_%H%M%S")
|
66
|
+
cont = {store_name.to_sym => store_item}
|
67
|
+
File.open(backup,'a'){|file| file.print(YAML.dump(cont))}
|
68
|
+
end
|
69
|
+
|
70
|
+
def add(item='new_item')
|
71
|
+
new_item={:opts=>{:short=>'-'+item[0], :long=>'--'+item, :desc=>item},
|
72
|
+
:title=>item, :cont=> [item]}
|
73
|
+
@help_cont[item.to_sym]=new_item
|
74
|
+
File.open(@source_file,'w'){|file| file.print YAML.dump(@help_cont)}
|
75
|
+
end
|
76
|
+
|
77
|
+
def remove(item)
|
78
|
+
store(item)
|
79
|
+
@help_cont.delete(item.to_sym)
|
80
|
+
File.open(@source_file,'w'){|file| file.print YAML.dump(@help_cont)}
|
81
|
+
end
|
82
|
+
|
46
83
|
def edit_help
|
47
84
|
system("emacs #{@source_file}")
|
48
85
|
end
|
49
86
|
|
50
87
|
def to_hiki
|
51
|
-
puts '<<<'
|
52
88
|
@help_cont.each_pair{|key,val|
|
53
89
|
if key==:head or key==:license
|
54
|
-
|
90
|
+
hiki_disp(val)
|
55
91
|
else
|
56
|
-
|
57
|
-
puts items[:title]
|
58
|
-
disp(items[:cont])
|
92
|
+
hiki_help(key)
|
59
93
|
end
|
60
94
|
}
|
61
|
-
puts '>>>'
|
62
95
|
end
|
63
96
|
|
64
|
-
def
|
65
|
-
|
66
|
-
|
97
|
+
def all_help
|
98
|
+
@help_cont.each_pair{|key,val|
|
99
|
+
if key==:head or key==:license
|
100
|
+
disp(val)
|
101
|
+
else
|
102
|
+
disp_help(key)
|
103
|
+
end
|
67
104
|
}
|
68
105
|
end
|
69
106
|
|
70
|
-
def
|
107
|
+
def hiki_help(key_word)
|
108
|
+
items =@help_cont[key_word]
|
109
|
+
puts "\n!!"+items[:title]+"\n"
|
110
|
+
hiki_disp(items[:cont])
|
111
|
+
end
|
112
|
+
|
113
|
+
def hiki_disp(lines)
|
114
|
+
lines.each{|line| puts "*#{line}"}
|
115
|
+
end
|
116
|
+
|
117
|
+
def disp_help(key_word)
|
118
|
+
print_separater
|
71
119
|
items =@help_cont[key_word]
|
72
120
|
puts items[:title]
|
73
121
|
disp(items[:cont])
|
122
|
+
print_separater
|
123
|
+
end
|
124
|
+
|
125
|
+
def disp(lines)
|
126
|
+
lines.each{|line| puts " *#{line}"}
|
127
|
+
end
|
128
|
+
|
129
|
+
def print_separater
|
130
|
+
print "---\n"
|
74
131
|
end
|
75
132
|
end
|
76
133
|
end
|
data/my_help.wiki/Home.md
CHANGED
@@ -30,6 +30,11 @@ commandや文法を覚えるのに苦労します.少しのkey(とっかかり
|
|
30
30
|
hikiでやろうとしていることの半分くらいはこのあたりのことなの
|
31
31
|
かもしれません.memoソフトでは,検索が必要となりますが,my_helpは
|
32
32
|
key(記憶のとっかかり)を提供することが目的です.
|
33
|
+
RPGでレベル上げとかアイテムを貯めるようにして,
|
34
|
+
プログラミングでスキルを発展させてください.
|
35
|
+
|
36
|
+
物覚えの悪い作者は,人の名前をitem分けして,こそっと使っています.
|
37
|
+
|
33
38
|
|
34
39
|
# 使用法
|
35
40
|
## インストール
|
@@ -56,6 +61,7 @@ Usage: my_help [options]
|
|
56
61
|
-m, --make make executables for all helps.
|
57
62
|
-c, --clean clean up exe dir.
|
58
63
|
--install_local install local after edit helps
|
64
|
+
--delete NAME delete NAME help
|
59
65
|
```
|
60
66
|
です.まず,-lでdefaultで入っているリストを見てください.
|
61
67
|
|
@@ -65,9 +71,35 @@ bob% bundle exec exe/my_help -l
|
|
65
71
|
["-l"]
|
66
72
|
Specific help file:
|
67
73
|
emacs_help
|
68
|
-
test_help
|
69
74
|
```
|
70
|
-
これで,CUIでemacs_help, e_h
|
75
|
+
これで,CUIでemacs_help, e_hが用意されています.
|
76
|
+
|
77
|
+
```
|
78
|
+
emacsのキーバインド
|
79
|
+
|
80
|
+
特殊キー操作
|
81
|
+
c-f, controlキーを押しながら 'f'
|
82
|
+
M-f, escキーを押した後一度離して'f'
|
83
|
+
操作の中断c-g, 操作の取り消し(Undo) c-x u
|
84
|
+
cc by Shigeto R. Nishitani, 2016
|
85
|
+
Usage: e_h [options]
|
86
|
+
-v, --version show program Version.
|
87
|
+
-c, --cursor Cursor移動
|
88
|
+
-e, --編集 Edit操作
|
89
|
+
-f, --ファイル File操作
|
90
|
+
-q, --終了 終了操作
|
91
|
+
-p, --ページ Page移動
|
92
|
+
-w, --ウィンドウ Window操作
|
93
|
+
-b, --バッファ Buffer操作
|
94
|
+
-m, --mode モード切り替え
|
95
|
+
--edit edit help contents
|
96
|
+
--to_hiki convert to hikidoc format
|
97
|
+
--all display all helps
|
98
|
+
--store [item] store [item] in back
|
99
|
+
--remove [item] remove [item] in back
|
100
|
+
--add [item] add new [item]
|
101
|
+
```
|
102
|
+
少し振る舞いに慣れてください.
|
71
103
|
|
72
104
|
## 独自のhelpを作る方法
|
73
105
|
さて,独自のhelpを作る方法です.まずは,
|
@@ -78,7 +110,12 @@ bob% bundle exec exe/my_help -i new_help
|
|
78
110
|
"/Users/bob/Github/my_help/lib/daddygongon/template_help"
|
79
111
|
cp /Users/bob/Github/my_help/lib/daddygongon/template_help /Users/bob/.my_help/new_help
|
80
112
|
```
|
81
|
-
で,new_helpというtemplateが用意されます.-e new_help
|
113
|
+
で,new_helpというtemplateが用意されます.-e new_helpで編集してください.
|
114
|
+
YAML形式で,格納されています.サンプルが,
|
115
|
+
```
|
116
|
+
my_help/lib/daddygongon
|
117
|
+
```
|
118
|
+
にあります.このあと,-mすると自動でnew_helpがexeディレクトリーに追加されます.
|
82
119
|
|
83
120
|
## 独自helpを使えるように
|
84
121
|
(これは,-mで自動的に行われるように修正されています)
|
@@ -98,8 +135,8 @@ cp /Users/bob/Github/my_help/lib/daddygongon/template_help /Users/bob/.my_help/n
|
|
98
135
|
- @target dirをmy_help/lib/daddygongonからENV['HOME']/.my_helpに変更
|
99
136
|
|
100
137
|
exe中のファイルをrakeで自動生成.
|
101
|
-
@target_dirにそれらのdata
|
102
|
-
exe中に実行ファイルを自動生成させている.
|
138
|
+
@target_dirにそれらのdataを保存.
|
139
|
+
その名前からexe中に実行ファイルを自動生成させている.
|
103
140
|
```
|
104
141
|
lib/daddygongon/
|
105
142
|
└── emacs_help
|
@@ -123,34 +160,32 @@ rake install:local
|
|
123
160
|
gem uninstall my_help
|
124
161
|
gem uninstall emacs_help
|
125
162
|
```
|
126
|
-
でそのdirをclean
|
163
|
+
でそのdirをcleanにしておくことが望ましい.下のuninstallの項目を参照.
|
127
164
|
|
128
|
-
|
165
|
+
-mでやっている中身は以下の通り.
|
129
166
|
```ruby
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
exe_cont << "help_file = File.expand_path(\"../../#{cont_name}\", __FILE__)\n"
|
142
|
-
exe_cont << "MyHelp::Command.run(help_file, ARGV)\n"
|
143
|
-
target_files.each{|name|
|
144
|
-
p ''
|
145
|
-
p target=File.join('exe',name)
|
146
|
-
File.open(target,'w'){|file|
|
147
|
-
print exe_cont
|
148
|
-
file.print exe_cont
|
167
|
+
def make_help
|
168
|
+
Dir.entries(@target_dir)[2..-1].each{|file|
|
169
|
+
next if file[0]=='#' or file[-1]=='~'
|
170
|
+
exe_cont="#!/usr/bin/env ruby\nrequire 'specific_help'\n"
|
171
|
+
exe_cont << "help_file = File.join(ENV['HOME'],'.my_help','#{file}')\n"
|
172
|
+
exe_cont << "SpecificHelp::Command.run(help_file, ARGV)\n"
|
173
|
+
[file, short_name(file)].each{|name|
|
174
|
+
p target=File.join('exe',name)
|
175
|
+
File.open(target,'w'){|file| file.print exe_cont}
|
176
|
+
FileUtils.chmod('a+x', target, :verbose => true)
|
177
|
+
}
|
149
178
|
}
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
179
|
+
install_local
|
180
|
+
end
|
181
|
+
|
182
|
+
def install_local
|
183
|
+
#中略
|
184
|
+
system "git add -A"
|
185
|
+
system "git commit -m 'update exe dirs'"
|
186
|
+
system "Rake install:local"
|
187
|
+
end
|
188
|
+
|
154
189
|
```
|
155
190
|
|
156
191
|
実装方法は,emacs_helpに
|
@@ -162,10 +197,30 @@ end
|
|
162
197
|
今の所,No.1の方を実装.No.2のためのhushデータは,
|
163
198
|
|
164
199
|
```ruby
|
200
|
+
# -*- coding: utf-8 -*-
|
165
201
|
require 'yaml'
|
166
202
|
require 'pp'
|
167
|
-
|
168
|
-
|
203
|
+
yaml =<<EOF
|
204
|
+
:file:
|
205
|
+
:opts:
|
206
|
+
:short: "-f"
|
207
|
+
:cont:
|
208
|
+
- c-x c-f, Find file, ファイルを開く
|
209
|
+
- c-x c-s, Save file, ファイルを保存
|
210
|
+
EOF
|
211
|
+
pp data=YAML.load(yaml)
|
212
|
+
print YAML.dump(data)
|
213
|
+
|
214
|
+
|
215
|
+
data0={:file=>
|
216
|
+
{:opts=>{:short=>"-f", :long=>"--ファイル", :desc=>"File操作"},
|
217
|
+
:title=>"ファイル操作file",
|
218
|
+
:cont=>
|
219
|
+
["c-x c-f, Find file, ファイルを開く
|
220
|
+
c-x c-s, Save file, ファイルを保存
|
221
|
+
c-x c-w, Write file NAME, ファイルを別名で書き込む"]}}
|
222
|
+
|
223
|
+
print YAML.dump(data0)
|
169
224
|
```
|
170
225
|
|
171
226
|
```
|