exe/githelp in githelp-0.3.4 vs exe/githelp in githelp-0.3.5
- old
+ new
@@ -31,10 +31,11 @@
}
dumpdata = {}
dumpdata['codes'] = []
dumpdata['defs'] = []
+ dumpdata['pages'] = []
#
# 関数/定数を評価"
#
puts "-----------------関数/定数を取得"
@@ -50,10 +51,11 @@
}
}
puts "-----------------GitHelpデータを検出"
@pagedata.each { |title,pagedata|
puts "...#{title}"
+ dumpdata['pages'] << title
processing_defs = false
codeindent = nil
pagedata.each { |line|
if !codeindent
if line =~ /^(\s*)code:/
@@ -72,11 +74,11 @@
puts line
if line =~ /^\%/ && !processing_defs
puts "'$'で始まる用例定義なしでコマンドを定義しようとしています"
exit
end
- dumpdata['defs'] << line
+ dumpdata['defs'] << "#{line} {#{dumpdata['pages'].length-1}}"
processing_defs = true
else
processing_defs = false
end
}
@@ -87,10 +89,14 @@
}
end
def githelp(pager)
data = JSON.parse(File.read(datafile))
+ unless data['pages'] # データ型式変換があったので
+ getdata
+ data = JSON.parse(File.read(datafile))
+ end
#
# 関数定義などをeval
#
data['codes'].each { |code|
@@ -127,33 +133,46 @@
listed[a[1]] = true
end
}
if pager == 'peco' then
+ no = {}
res = IO.popen(pager, "r+") {|io|
list.each_with_index { |entry,ind|
- io.puts "#[#{ind}] #{entry[0]}"
+ entry[0].sub!(/\s*{(\d*)}$/,'')
+ entry[1].sub!(/\s*{(\d*)}$/,'')
+ no[entry[0]] = $1.to_i
+ io.puts "[#{ind}] #{entry[0]}"
io.puts " #{entry[1]}"
}
io.close_write
io.gets
}
if res
- if res =~ /^\#\[(\d+)\]/
+ if res =~ /^\[(\d+)\]/
+ desc = list[$1.to_i][0]
cmd = list[$1.to_i][1]
else
+ desc = ''
+ list.each { |entry|
+ desc = entry[0] if entry[1].sub(/^\s*/,'') == res.chomp.sub(/^\s*/,'')
+ }
cmd = res.sub(/^\s*/,'')
end
- print "「#{cmd.chomp}」 を実行しますか? "
+
+ puts "データ: http://scrapbox.io/GitHelp/#{data['pages'][no[desc]]}"
+ puts
+ puts "#{desc} ために"
+ print "コマンド「#{cmd.chomp}」 を実行しますか? (Y) "
ans = STDIN.gets
if ans =~ /^y/i || ans == "\n"
system cmd
end
end
else
res = IO.popen(pager, "w") {|io|
list.each_with_index { |entry,ind|
- io.puts "#[#{ind}] #{entry[0]}"
+ io.puts "[#{ind}] #{entry[0]}"
io.puts " #{entry[1]}"
}
}
end
end