Created
November 19, 2016 07:53
-
-
Save aashishdhawan/44f0438d6659a40c157fa8569c4d2a8b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
_get_repo() { | |
echo "$1" | sed -e "s/.git$//" -e "s/.*github.com[:/]\(.*\)/\1/" | |
} | |
_build_url() { | |
# shellcheck disable=SC2039 | |
local upstream origin branch repo pr_url target | |
upstream="$(git config --get remote.upstream.url)" | |
origin="$(git config --get remote.origin.url)" | |
branch="$(git symbolic-ref --short HEAD)" | |
repo="$(_get_repo "$origin")" | |
pr_url="https://github.com/$repo/pull/new" | |
target="$1" | |
test -z "$target" && target="master" | |
if [ -z "$upstream" ]; then | |
echo "$pr_url/$target...$branch" | |
else | |
# shellcheck disable=SC2039 | |
local origin_name upstream_name | |
origin_name="$(echo "$repo" | cut -f1 -d'/')" | |
upstream_name="$(_get_repo "$upstream" | cut -f1 -d'/')" | |
echo "$pr_url/$upstream_name:$target...$origin_name:$branch" | |
fi | |
} | |
# shellcheck disable=SC2039 | |
# shellcheck disable=SC2039 | |
url="$(_build_url "$*")" | |
if [ "$(uname -s)" = "Darwin" ]; then | |
open "$url" 2> /dev/null | |
else | |
xdg-open "$url" > /dev/null 2> /dev/null | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment