1
0
mirror of https://github.com/dcarrillo/prezto.git synced 2024-11-20 16:31:12 +00:00
prezto/plugins/git/functions/git-hub

46 lines
1004 B
Plaintext
Raw Normal View History

2012-02-01 04:37:51 +00:00
#
# Opens a GitHub repository in the default browser.
#
# Authors:
# Sorin Ionescu <sorin.ionescu@gmail.com>
#
local remote branches branch current_branch file url
remote="${1:-origin}"
url=$(
2011-10-12 03:13:58 +00:00
git config -l \
| grep "remote.${remote}.url" \
| sed -En "s/remote.${remote}.url=(git|https?)(@|:\/\/)github.com(:|\/)(.+)\/(.+).git/https:\/\/github.com\/\4\/\5/p"
2011-10-12 03:13:58 +00:00
)
branches=($(
2012-01-24 05:50:51 +00:00
git branch -r | sed -e "/${remote}\/HEAD -> ${remote}/d" -e "s/^[[:space:]]*${remote}\///g"
))
current_branch="$(git-branch)"
branch="${2:-master}"
file="$3"
if [[ -z "$2" ]]; then
if (( $branches[(I)$current_branch] != 0 )); then
branch="$current_branch"
else
branch='master'
fi
fi
2011-10-12 03:13:58 +00:00
if [[ -n "$url" ]]; then
url="${url}/tree/${branch}/${file}"
2011-10-12 03:13:58 +00:00
if (( $+commands[$BROWSER] )); then
"$BROWSER" "$url"
return 0
else
2012-01-19 07:28:01 +00:00
print "$0: browser not set or set to a non-existent browser" >&2
2011-10-12 03:13:58 +00:00
return 1
fi
else
2012-01-19 07:28:01 +00:00
print "$0: not a Git repository or remote origin not set" >&2
2011-10-12 03:13:58 +00:00
return 1
fi