-
Notifications
You must be signed in to change notification settings - Fork 0
/
github.sh.cmd
40 lines (34 loc) · 1.13 KB
/
github.sh.cmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/bin/sh
# Script to open a browser to current branch
# Repo formats:
# ssh git@github.com:richo/gh_pr.git
# http https://richoH@github.com/richo/gh_pr.git
# git git://github.com/richo/gh_pr.git
username=`git config --get github.user`
get_repo() {
git remote -v | grep ${@:-$username} | while read remote; do
if repo=`echo $remote | grep -E -o "git@github.com:[^ ]*"`; then
echo $repo | sed -e "s/^git@github\.com://" -e "s/\.git$//"
exit 1
fi
if repo=`echo $remote | grep -E -o "https?://([^@]*@)?github.com/[^ ]*\.git"`; then
echo $repo | sed -e "s|^https?://||" -e "s/^.*github\.com\///" -e "s/\.git$//"
exit 1
fi
if repo=`echo $remote | grep -E -o "git://github.com/[^ ]*\.git"`; then
echo $repo | sed -e "s|^git://github.com/||" -e "s/\.git$//"
exit 1
fi
done
if [ $? -eq 0 ]; then
echo "Couldn't find a valid remote" >&2
exit 1
fi
}
echo ${#x[@]}
if repo=`get_repo $@`; then
branch=`git symbolic-ref HEAD 2>/dev/null`
echo "http://github.com/$repo/pull/new/${branch##refs/heads/}"
else
exit 1
fi