2011-10-12 05:13:58 +02:00
|
|
|
# Open the GitHub repository in the browser.
|
2012-01-19 23:32:27 +01:00
|
|
|
local remote branches branch current_branch url
|
|
|
|
|
|
|
|
remote="${1:-origin}"
|
|
|
|
url=$(
|
2011-10-12 05:13:58 +02:00
|
|
|
git config -l \
|
2012-01-19 23:32:27 +01:00
|
|
|
| grep "remote.${remote}.url" \
|
|
|
|
| sed -En "s/remote.${remote}.url=(git|https?)(@|:\/\/)github.com(:|\/)(.+)\/(.+).git/https:\/\/github.com\/\4\/\5/p"
|
2011-10-12 05:13:58 +02:00
|
|
|
)
|
2012-01-19 23:32:27 +01:00
|
|
|
branches=($(
|
|
|
|
git branch -a \
|
|
|
|
| grep "remotes/${remote}" \
|
|
|
|
| sed -e 's/[ \*]*//g' -e "s:remotes/${remote}/::g"
|
|
|
|
))
|
|
|
|
current_branch="$(git-branch)"
|
|
|
|
branch="${2:-master}"
|
|
|
|
|
|
|
|
if [[ -z "$2" ]]; then
|
|
|
|
if (( $branches[(I)$current_branch] != 0 )); then
|
|
|
|
branch="$current_branch"
|
|
|
|
else
|
|
|
|
branch='master'
|
|
|
|
fi
|
|
|
|
fi
|
2011-10-12 05:13:58 +02:00
|
|
|
|
|
|
|
if [[ -n "$url" ]]; then
|
2012-01-19 23:32:27 +01:00
|
|
|
url="${url}/tree/${branch}"
|
2011-10-12 05:13:58 +02:00
|
|
|
|
|
|
|
if (( $+commands[$BROWSER] )); then
|
|
|
|
"$BROWSER" "$url"
|
|
|
|
return 0
|
|
|
|
else
|
|
|
|
print "fatal: Browser not set or set to a non-existent browser." >&2
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
print "fatal: Not a Git repository or origin remote not set." >&2
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|