exe/githelp in githelp-0.1.4 vs exe/githelp in githelp-0.2.1
- old
+ new
@@ -1,79 +1,54 @@
#!/usr/bin/env ruby
-# coding: utf-8
+
+include Githelp
+
+require 're_expand'
+require 'json'
+
+DATAFILE = File.expand_path("~/.githelp")
+
+data = JSON.parse(File.read(DATAFILE))
+
#
-# GitHelp: ExpandHelpでGitを使いこなす
+# 関数定義などをeval
#
-# % githelp # usage
-# % githelp README 8時間 比較 # マッチする候補を表示
-# % githelp -i README 8時間 比較 # マッチする候補を表示して選択
-#
+data['codes'].each { |code|
+ eval code
+}
-# 追加すべきデータはdata.txtに書く
+g = ExpandRuby::Generator.new # re_expandのジェネレータ
-require "githelp"
-require "bundler/setup"
+#
+# GitHelpエントリ
+#
+lines = []
-include Githelp
+data['defs'].each { |line|
+ if line =~ /^\s*\$\s*(.*)$/ # $....
+ lines << $1
+ elsif line =~ /^\s*\%\s*(.*)$/ # %....
+ cmd = $1
+ lines.each { |l|
+ desc = eval('"' + l + '"')
+ g.add desc.force_encoding('utf-8'), cmd.force_encoding('utf-8')
+ }
+ lines = []
+ end
+}
-unless git_check
- STDERR.puts "Use 'githelp' in a Git repository."
- exit
-end
+res = g.generate " #{args.join(' ')} "
-progpath = $0
-if File.symlink?(progpath)
- progpath = File.readlink(progpath)
-end
-progdir = "#{File.dirname(progpath)}"
-
-opt_i = false
-opt_x = nil
-i = 0
-ARGV.dup.each { |arg|
- if arg == "-i"
- opt_i = true
- ARGV.delete_at(i)
- elsif opt_x == ''
- opt_x = arg.to_i
- ARGV.delete_at(i)
- elsif arg =~ /^-x(\d*)/
- if $1.to_s != ''
- opt_x = $1.to_i
- else
- opt_x = ''
- end
- ARGV.delete_at(i)
+listed = {}
+list = res[0].find_all { |a| # 0 ambig
+ if listed[a[1]]
+ false
else
- i += 1
+ listed[a[1]] = true
end
}
-list = githelp(" #{args.join(' ')} ")
-if opt_x then
- cmd = list[opt_x][1]
- STDERR.puts cmd
- system "PATH=$PATH:#{progdir}/bin; (#{cmd})"
- exit
-else
- IO.popen("more","w"){ |f|
- list.each_with_index { |entry,ind|
- f.puts "[#{ind}] #{entry[0]}"
- f.puts " % " + entry[1]
- }
- }
-end
+list.each_with_index { |entry,ind|
+ puts "#[#{ind}] #{entry[0]}"
+ puts " #{entry[1]}"
+}
-if opt_i then
- if list.length > 0 then
- print "実行するコマンドの番号を入力して下さい > "
- s = STDIN.readline
- if s =~ /[0-9]/ then
- i = s.to_i
- if i >= 0 && i < list.length then
- cmd = list[i][1]
- STDERR.puts cmd
- system "PATH=$PATH:#{progdir}/bin; (#{cmd})"
- end
- end
- end
-end