u16suzuの blog

日々学んだことのメモブログです。

gem のコードを git clone して RubyMine で開くスクリプト

以下を /usr/local/bin に置いて、 chmod a+x clone_and_open.rb しておく。

clone_and_open.rb https://github.com/u16suzu/foo すると ~/src にダウンロードされる。

clone_and_open.rb

#!/usr/bin/env ruby

class CodeReader
  # clone and open
  #
  # git repository を ~/src に clone して RubyMine で開くコマンド
  def clone_and_open(uri=ARGV[0])
    dir_name = uri.split("/")[-2]
    repo_name= uri.split("/")[-1]

    system "mkdir -p ~/src/#{dir_name}"

    # password入力を避けるために ssh 形式で clone する
    system "git clone git@github.com:#{dir_name}/#{repo_name}.git ~/src/#{dir_name}/#{repo_name}"

    system "mine ~/src/#{dir_name}/#{repo_name}"
  end
end

CodeReader.new.clone_and_open