LoginSignup
43
46

More than 5 years have passed since last update.

作業中ブランチのプルリクエストをブラウザで開く

Last updated at Posted at 2014-06-05

WIPとかプルリクエスト出した後にゴチャゴチャ作業してる状態の時にちょくちょくgithubの画面開きたいのでコマンドにした。

bash
propen() {
    local current_branch_name=$(git symbolic-ref --short HEAD | xargs perl -MURI::Escape -e 'print uri_escape($ARGV[0]);')
    git config --get remote.origin.url | sed -e "s/^.*[:\/]\(.*\/.*\).git$/https:\/\/github.com\/\1\//" | sed -e "s/$/pull\/${current_branch_name}/" | xargs open
}
bash
propen() {
    local current_branch_name=$(git symbolic-ref --short HEAD | xargs perl -MURI::Escape -e 'print uri_escape($ARGV[0]);')
    hub browse -- pull/${current_branch_name}
}

zshとbashで動いた。

最初hubコマンド必要だったけどgitとperlだけ入ってればできるようにした(sedコマンド入って読み辛くなったけど)がGitHub:Eなどでうまく動かな時はhubコマンドの方に置き換えてみて。

URLエンコードにperlを介する必要があったがgit入ってればperlあるしいい気がする。

このプルリクエスト出した時はpatch-1ブランチで作業してた。

propen

とコマンドを打つとブラウザで勝手に https://github.com/hatena/Hatena-Textbook/pull/patch-1 を開き、https://github.com/hatena/Hatena-Textbook/pull/6 へリダイレクトされる。
リダイレクトされるのは単にGitHubの便利機能らしい。

同名ブランチあったらどうなるんだろう。

43
46
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
43
46