メモメモメモ

ほんとうにめも

【Shell】GithubのPullRequest作成ページを一発で開く関数(ワンライナー)

関数の定義

.zsh_alias.bash_aliasに書いておく。

# カレントブランチから$1ブランチへのPullRequestを開く
function opr() {
  parentBranch=$1
  currentBranch=`git branch | grep "*"`
  repoName=$(git remote show origin -n | ruby -ne 'puts /^\s*Fetch.*:(.*).git/.match($_)[1] rescue nil')

  open -a /Applications/Google\ Chrome.app  https://github.com/${repoName/* /}/compare/${parentBranch/* /}...${currentBranch/* /}
}

使用例

opr dev (currentブランチからdevブランチへ) opr master (currentブランチからmasterブランチへ) など。

簡単に解説

第一引数$1にターゲットブランチを渡す。 git branch | grep "*"で現在のブランチを取得出来るので、そこに対してPullRequestを出している。

補足

ChromeアプリへのPathは自分のPC内のに合わせてください。 もちろん、safarifirefoxでも可。