Sha256: 61f85b7881a599ae494cc6862f963f3acdf412120ebb6fe7cd7472ef5ae777d2

Contents?: true

Size: 1.51 KB

Versions: 3

Compression:

Stored size: 1.51 KB

Contents

#!/usr/bin/env ruby
# coding: utf-8
#
# GitHelp: ExpandHelpでGitを使いこなす
#
# % githelp                         # usage
# % githelp README 8時間 比較       # マッチする候補を表示
# % githelp -i README 8時間 比較    # マッチする候補を表示して選択
#

# 追加すべきデータはdata.txtに書く

require "bundler/setup"
require "githelp"

include Githelp

unless git_check
  STDERR.puts "Use 'githelp' in a Git repository."
  exit
end

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)
  else
    i += 1
  end
}

list = githelp(" #{args.join(' ')} ")
if opt_x then
  cmd = list[opt_x][1]
  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

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]
        puts cmd
        system "PATH=$PATH:#{progdir}/bin; (#{cmd})"
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
githelp-0.1.3 exe/githelp
githelp-0.1.2 exe/githelp
githelp-0.1.1 exe/githelp