-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgithub.zsh
51 lines (42 loc) · 901 Bytes
/
github.zsh
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
41
42
43
44
45
46
47
48
49
50
51
#
# Opens the github page for a repo/branch in your browser.
#
# gh [remote] [branch]
gh() {
git rev-parse 2>/dev/null
if [[ $? != 0 ]]
then
echo "Not a git repository."
return 1
fi
remote="origin"
if [ ! -z "$1" ]
then
remote="$1"
fi
remote_url="remote.${remote}.url"
giturl=$(git config --get $remote_url)
if [ -z "$giturl" ]
then
echo "$remote_url not set."
return 1
fi
giturl=$(echo "$giturl" | cut -d '@' -f 2)
#giturl=${giturl/git\@github\.com\:\https://github.com/}
giturl=${giturl%\.git}
giturl=$(echo "$giturl" | tr ':' '/')
giturl="https://$giturl"
if [ -z "$2" ]
then
branch=$(git rev-parse --abbrev-ref HEAD | sed 's/#/%23/' 2>/dev/null)
else
branch="$2"
fi
if [ ! -z "$branch" ]
then
giturl="${giturl}/tree/${branch}"
fi
echo "Opening GitURL $giturl"
open $giturl
return 0
}