forked from paulirish/git-open
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgh.sh
More file actions
executable file
·46 lines (37 loc) · 670 Bytes
/
gh.sh
File metadata and controls
executable file
·46 lines (37 loc) · 670 Bytes
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
#!/bin/sh
#
# Opens the github page for a repo/branch in your browser.
#
# gh [remote] [branch]
git rev-parse 2>/dev/null
if [[ $? != 0 ]]
then
echo "Not a git repository."
exit 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."
exit 1
fi
giturl=${giturl/git\@github\.com\:/https://github.com/}
giturl=${giturl%\.git}
if [ -z "$2" ]
then
branch=$(git rev-parse --abbrev-ref HEAD 2>/dev/null)
else
branch="$2"
fi
if [ ! -z "$branch" ]
then
giturl="${giturl}/tree/${branch}"
fi
open $giturl
exit 0