forked from mhartl/git-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit-open
More file actions
executable file
·41 lines (36 loc) · 1.07 KB
/
Copy pathgit-open
File metadata and controls
executable file
·41 lines (36 loc) · 1.07 KB
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
#!/bin/sh
# Copyright (c) 2013 Michael Hartl
# Copyright (c) 2013 Aleksandar Simic
# Released under the MIT License (http://opensource.org/licenses/MIT)
# Opens the remote page for the repo (OS X only).
URL=`git config --get remote.origin.url`
CURRENT_BRANCH=`git rev-parse --abbrev-ref HEAD`
SERVICE=stash
PROTOCOL=ssh
if [[ $URL =~ bitbucket ]]
then
SERVICE=bitbucket
elif [[ $URL =~ github ]]
then
SERVICE=github
fi
if [[ $URL =~ https:// || $URL =~ http:// ]]
then
PROTOCOL=http
fi
case $SERVICE-$PROTOCOL in
stash-ssh )
# If it's ssh, drop the port
GIT_PATTERN='s/(.*)@([^:]*):?([^\/]*)\/([^\/]*)\/(.*)\.git/https:\/\/\2\/projects\/\4\/repos\/\5\/browse\?at='"$CURRENT_BRANCH"/
;;
stash-http )
GIT_PATTERN='s/(.*)@([^:\/]*)(:?[^\/]*)\/(.*)scm\/([^\/]*)\/(.*)\.git/https:\/\/\2\3\/\4projects\/\5\/repos\/\6\/browse\?at='"$CURRENT_BRANCH"/
;;
*-ssh )
GIT_PATTERN='s/(.*)@(.*):(.*)\.git/https:\/\/\2\/\3/'
;;
*-http )
GIT_PATTERN='s/https?\:\/\/(([^@]*)@)?(.*)\.git/https:\/\/\3/'
;;
esac
echo $URL | sed -E $GIT_PATTERN | xargs open